Skip to content

web/elements: test that ak-mdx does not evaluate API-supplied content - #24524

Merged
GirlBossRush merged 1 commit into
goauthentik:mainfrom
kah-ja:web/mdx-content-commonmark
Oct 22, 2026
Merged

GirlBossRush merged 1 commit into
goauthentik:mainfrom
kah-ja:web/mdx-content-commonmark

Conversation

@kah-ja

@kah-ja kah-ja commented Jul 30, 2026 •

Copy link
Copy Markdown
Contributor

What

<ak-mdx> renders two kinds of source:

  • documentation authored in-tree and bundled with the web interface, passed as url,
  • content that comes back from the API, passed as content — user.attributes.notes (UserNotesCard.ts), group.attributes.notes (GroupViewPage.ts) and blueprint descriptions (BlueprintListPage.ts).

Both were compiled with the same compile() call, i.e. as MDX. MDX parses expressions ({...}), JSX and ESM import/export in addition to Markdown, and those are evaluated when the compiled module is run by run() in delegateRender(). So a source that came from the API was evaluated as code in the admin interface.

The BrandedHTMLPolicy DOMPurify pass in front of the compiler does not cover this: it operates on HTML, and neither {...} nor an export statement is HTML — both reach compile() unchanged.

Reported privately as GHSA-5vfm-49hj-h95w.

Change

Thread the compile format through delegateRender():

  • url (bundled documentation) keeps format: "mdx" — unchanged behaviour,
  • content (from the API) gets format: "md", i.e. CommonMark, so nothing in it is evaluated.

This is a parser-level distinction rather than a filter, so it does not depend on enumerating constructs. The DOMPurify pass stays where it is.

Behaviour

Measured against the pinned versions (@mdx-js/mdx 3.1.1, dompurify 3.4.12, react 19.2.8), rendering through the same compile()/run() pipeline the element uses:

Source in content before after
{...} expression evaluated rendered as text
export const … = … evaluated rendered as text
import "data:text/javascript,…" evaluated rendered as text
<div>{…}</div> evaluated rendered as text
headings, bold/italic, lists, GFM tables, fenced code with highlighting, links rendered rendered, unchanged

One intentional difference: raw HTML in content (for example <strong>hi</strong> in a note) now renders as text instead of as an element. Markdown syntax is unaffected.

Tests

web/src/elements/ak-mdx/content-format.unit.test.ts covers that a source is evaluated under mdx and inert under md, and that CommonMark still renders.

A note on running them locally: web/vite.config.js points the Unit Tests project at ./tsconfig.unit.json, which is not in the tree, so vitest --project "Unit Tests" fails during transform before any test runs — including for the existing custom-elements-get-name.unit.test.ts. I therefore ran the assertions of the new test as a plain node script against web/node_modules (all four pass) rather than through vitest. Happy to look at the missing tsconfig in a separate PR if that is useful.

@kah-ja
kah-ja requested a review from a team as a code owner July 30, 2026 17:31
@netlify

netlify Bot commented Jul 30, 2026

Copy link
Copy Markdown

✅ Deploy Preview for authentik-storybook ready!

Name Link
🔨 Latest commit 57669f7
🔍 Latest deploy log https://app.netlify.com/projects/authentik-storybook/deploys/6a6b8a80183e7a00089f7b3a
😎 Deploy Preview https://deploy-preview-24524--authentik-storybook.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@netlify

netlify Bot commented Jul 30, 2026

Copy link
Copy Markdown

✅ Deploy Preview for authentik-integrations ready!

Name Link
🔨 Latest commit 57669f7
🔍 Latest deploy log https://app.netlify.com/projects/authentik-integrations/deploys/6a6b8a8061851a00089291b3
😎 Deploy Preview https://deploy-preview-24524--authentik-integrations.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@netlify

netlify Bot commented Jul 30, 2026

Copy link
Copy Markdown

✅ Deploy Preview for authentik-docs ready!

Name Link
🔨 Latest commit 57669f7
🔍 Latest deploy log https://app.netlify.com/projects/authentik-docs/deploys/6a6b8a803fb1e300085b0308
😎 Deploy Preview https://deploy-preview-24524--authentik-docs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@GirlBossRush

Copy link
Copy Markdown
Contributor

Hi @kah-ja,

Thank you for the excellent PR. We're reworking our in-app markdown compilation to remove React from our dependency list. There's also some ongoing planning surrounding Content Security Policy support and trusted inputs.

You can track progress on this effort at #21949

@GirlBossRush GirlBossRush self-assigned this Jul 31, 2026
@GirlBossRush GirlBossRush added area:frontend Features or issues related to the browser, TypeScript, Node.js, etc status/reviewing thanks for opening, we're taking a look labels Jul 31, 2026
Render <ak-mdx> with content that calls a probe from an expression and
from an ESM export, and assert the probe never runs, while Markdown
still renders.

Co-authored-by: Jan Kahmen <[email protected]>
@GirlBossRush
GirlBossRush force-pushed the web/mdx-content-commonmark branch from 57669f7 to ee9ed81 Compare October 22, 2026 16:48
@GirlBossRush GirlBossRush changed the title web/elements: compile ak-mdx content from the API as CommonMark web/elements: test that ak-mdx does not evaluate API-supplied content Oct 22, 2026
@github-project-automation github-project-automation Bot moved this from Todo to In Progress in authentik Core Oct 22, 2026
@GirlBossRush
GirlBossRush enabled auto-merge (squash) October 22, 2026 16:56
@GirlBossRush GirlBossRush removed the status/reviewing thanks for opening, we're taking a look label Oct 22, 2026
@GirlBossRush GirlBossRush moved this from In Progress to Done in authentik Core Oct 22, 2026
@GirlBossRush

Copy link
Copy Markdown
Contributor

This PR now targets main with a component test only. The fix above will be backported to version-2026.8 separately.

Thanks @kah-ja for the report and the fix.

@codecov

codecov Bot commented Oct 22, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 92.35%. Comparing base (3abd6e5) to head (ee9ed81).
⚠️ Report is 2 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #24524      +/-   ##
==========================================
- Coverage   92.38%   92.35%   -0.04%     
==========================================
  Files        1190     1190              
  Lines       80153    80153              
  Branches     4351     4351              
==========================================
- Hits        74048    74022      -26     
- Misses       6039     6065      +26     
  Partials       66       66              
Flag Coverage Δ
conformance 32.31% <ø> (+<0.01%) ⬆️
e2e 36.99% <ø> (+<0.01%) ⬆️
integration 28.83% <ø> (-0.37%) ⬇️
rust 44.42% <ø> (ø)
unit 94.03% <ø> (+<0.01%) ⬆️
unit-migrate 94.03% <ø> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

@GirlBossRush
GirlBossRush merged commit aeb0989 into goauthentik:main Oct 22, 2026
163 checks passed
kensternberg-authentik added a commit that referenced this pull request Oct 22, 2026
* main:
  web/elements: test that ak-mdx does not evaluate API-supplied content (#24524)
kensternberg-authentik added a commit that referenced this pull request Oct 22, 2026
…/sidebar-footer-dependency

* web/sidebar/validate-sidebar-entries:
  The test exists and passes.
  Moving the load of the AdminOverviewPage to the entrypoint. The idea is to have the dashboard as live as possible as early as possible.  Putting into Routes made Routes into a browser-only feature, and it could not be unit tested without this move.
  web/elements: test that ak-mdx does not evaluate API-supplied content (#24524)
kensternberg-authentik added a commit that referenced this pull request Oct 22, 2026
…ts/sidebar-api-disconnect

* web/elements/sidebar-footer-dependency: (27 commits)
  The test exists and passes.
  Moving the load of the AdminOverviewPage to the entrypoint. The idea is to have the dashboard as live as possible as early as possible.  Putting into Routes made Routes into a browser-only feature, and it could not be unit tested without this move.
  web/elements: test that ak-mdx does not evaluate API-supplied content (#24524)
  root: require Node.js 24.22.1 (#27093)
  Formatter opinions.
  That side effect infected downstream tests. Darnit.
  web/admin: Simplify sidebar entries handling
  website/docs: change routing info after 2026.8 changes (#27109)
  core: bump astral-sh/uv from 0.13.4 to 0.13.5 in /lifecycle/container (#27096)
  flows: avoid saving plan history when inspector inaccessible (#27089)
  core: bump pyo3 from 0.29.0 to 0.30.1 (#27099)
  core: bump arc-swap from 1.9.2 to 1.9.3 (#27098)
  core: bump pyroscope-io from 1.2.5 to 1.3.0 (#27100)
  core: bump pyo3-build-config from 0.29.0 to 0.30.1 (#27097)
  core: bump dexidp/dex from v2.46.0 to v2.46.1 in /tests/e2e (#27095)
  website/integrations: VCF 9: touch up (#27094)
  lifecycle/container: add a distroless version of the server image (#26321)
  ci: run tests in the server image (#26510)
  packages/client-ts: Generate imports with `.js` extensions (#27029)
  core: bump djangorestframework from 3.18.1 to 3.18.3 (#26838)
  ...
@GirlBossRush GirlBossRush added the backport/version-2026.8 Add this label to PRs to backport changes to version-2026.8 label Oct 22, 2026
@authentik-cherry-pick

Copy link
Copy Markdown
Contributor

🍒 Cherry-pick to version-2026.8 created: #27115

GirlBossRush added a commit that referenced this pull request Oct 22, 2026
…#24524)

Render <ak-mdx> with content that calls a probe from an expression and
from an ESM export, and assert the probe never runs, while Markdown
still renders.

Co-authored-by: Teffen Ellis <[email protected]>
GirlBossRush added a commit that referenced this pull request Oct 22, 2026
…24524 to version-2026.8) (#27115)

* web/elements: compile ak-mdx content from the API as CommonMark

`<ak-mdx>` renders two kinds of source: documentation that is authored
in-tree and bundled with the web interface (`url`), and content that
comes back from the API (`content`) - user and group notes, and
blueprint descriptions.

Both were compiled as MDX. MDX evaluates expressions (`{...}`) and ESM
imports/exports of a source when the compiled module runs, so API
content was evaluated as code. The DOMPurify pass in front of the
compiler works at the HTML level and does not see either construct.

Compile `content` as CommonMark instead, so no part of it is evaluated,
and keep MDX for the bundled documentation. Reported privately as
GHSA-5vfm-49hj-h95w.

* web/elements: test that ak-mdx does not evaluate API-supplied content (#24524)

Render <ak-mdx> with content that calls a probe from an expression and
from an ESM export, and assert the probe never runs, while Markdown
still renders.

Co-authored-by: Teffen Ellis <[email protected]>

---------

Co-authored-by: Jan Kahmen <[email protected]>
Co-authored-by: Jan Kahmen <[email protected]>
Co-authored-by: Teffen Ellis <[email protected]>
@authentik-cherry-pick

Copy link
Copy Markdown
Contributor

🍒 Cherry-pick to version-2026.5 created: #27121

GirlBossRush added a commit that referenced this pull request Oct 22, 2026
…#24524)

Render <ak-mdx> with content that calls a probe from an expression and
from an ESM export, and assert the probe never runs, while Markdown
still renders.

Co-authored-by: Teffen Ellis <[email protected]>
GirlBossRush added a commit that referenced this pull request Oct 22, 2026
…24524 to version-2026.5) (#27121)

* web/elements: compile ak-mdx content from the API as CommonMark

`<ak-mdx>` renders two kinds of source: documentation that is authored
in-tree and bundled with the web interface (`url`), and content that
comes back from the API (`content`) - user and group notes, and
blueprint descriptions.

Both were compiled as MDX. MDX evaluates expressions (`{...}`) and ESM
imports/exports of a source when the compiled module runs, so API
content was evaluated as code. The DOMPurify pass in front of the
compiler works at the HTML level and does not see either construct.

Compile `content` as CommonMark instead, so no part of it is evaluated,
and keep MDX for the bundled documentation. Reported privately as
GHSA-5vfm-49hj-h95w.

* web/elements: test that ak-mdx does not evaluate API-supplied content (#24524)

Render <ak-mdx> with content that calls a probe from an expression and
from an ESM export, and assert the probe never runs, while Markdown
still renders.

Co-authored-by: Teffen Ellis <[email protected]>

---------

Co-authored-by: Jan Kahmen <[email protected]>
Co-authored-by: Jan Kahmen <[email protected]>
Co-authored-by: Teffen Ellis <[email protected]>
@kah-ja

kah-ja commented Oct 23, 2026

Copy link
Copy Markdown
Contributor Author

We found this vulnerability during a penetration test at turingpoint.

Thanks for the quick fix! The associated GitHub Security Advisory (GHSA-5vfm-49hj-h95w) can now be published.

kensternberg-authentik added a commit that referenced this pull request Nov 5, 2026
…single-shadowdom-sidebar

* web/elements/sidebar-api-disconnect: (28 commits)
  Fix some merge issues.
  The test exists and passes.
  Moving the load of the AdminOverviewPage to the entrypoint. The idea is to have the dashboard as live as possible as early as possible.  Putting into Routes made Routes into a browser-only feature, and it could not be unit tested without this move.
  web/elements: test that ak-mdx does not evaluate API-supplied content (#24524)
  root: require Node.js 24.22.1 (#27093)
  Formatter opinions.
  That side effect infected downstream tests. Darnit.
  web/admin: Simplify sidebar entries handling
  website/docs: change routing info after 2026.8 changes (#27109)
  core: bump astral-sh/uv from 0.13.4 to 0.13.5 in /lifecycle/container (#27096)
  flows: avoid saving plan history when inspector inaccessible (#27089)
  core: bump pyo3 from 0.29.0 to 0.30.1 (#27099)
  core: bump arc-swap from 1.9.2 to 1.9.3 (#27098)
  core: bump pyroscope-io from 1.2.5 to 1.3.0 (#27100)
  core: bump pyo3-build-config from 0.29.0 to 0.30.1 (#27097)
  core: bump dexidp/dex from v2.46.0 to v2.46.1 in /tests/e2e (#27095)
  website/integrations: VCF 9: touch up (#27094)
  lifecycle/container: add a distroless version of the server image (#26321)
  ci: run tests in the server image (#26510)
  packages/client-ts: Generate imports with `.js` extensions (#27029)
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:frontend Features or issues related to the browser, TypeScript, Node.js, etc backport/version-2026.5 Add this label to PRs to backport changes to version-2026.5 backport/version-2026.8 Add this label to PRs to backport changes to version-2026.8

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

2 participants