Skip to content

web/admin: handle non-string values in formatUUID to prevent Event Log crash#20804

Merged
BeryJu merged 1 commit intogoauthentik:mainfrom
tysoncung:fix/event-log-format-uuid-type-error
Mar 20, 2026
Merged

web/admin: handle non-string values in formatUUID to prevent Event Log crash#20804
BeryJu merged 1 commit intogoauthentik:mainfrom
tysoncung:fix/event-log-format-uuid-type-error

Conversation

@tysoncung
Copy link
Contributor

What

Fixes #20803

When navigating to Events → Log, the page crashes with:

TypeError: s.substring is not a function
    at formatUUID (utils.ts:13)

Why

The formatUUID function in web/src/admin/events/utils.ts assumes its argument is always a string. However, event.context.device.pk from the API can be a non-string value (e.g., integer or UUID object), since EventContext values are dynamically typed (EventContextProperty). When formatUUID receives a non-string, calling .substring() throws a TypeError, crashing the entire Event Log page.

How

Added a type guard at the top of formatUUID that checks typeof hex !== "string" and coerces to String() if needed, rather than crashing. This is a minimal, defensive fix that keeps the rest of the function logic unchanged.

Testing

  • Verified the fix handles number, undefined, and null inputs without throwing
  • Existing string inputs continue to format correctly

… crash

When event context contains a device with a non-string pk value,
formatUUID crashes with TypeError: s.substring is not a function,
preventing the entire Event Log page from loading.

Add a type guard to coerce non-string values to their string
representation instead of crashing.

Fixes goauthentik#20803
@tysoncung tysoncung requested a review from a team as a code owner March 9, 2026 17:09
@netlify
Copy link

netlify bot commented Mar 9, 2026

Deploy Preview for authentik-storybook ready!

Name Link
🔨 Latest commit d692cbc
🔍 Latest deploy log https://app.netlify.com/projects/authentik-storybook/deploys/69aefee4637ff40008bd376f
😎 Deploy Preview https://deploy-preview-20804--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
Copy link

netlify bot commented Mar 9, 2026

Deploy Preview for authentik-docs ready!

Name Link
🔨 Latest commit d692cbc
🔍 Latest deploy log https://app.netlify.com/projects/authentik-docs/deploys/69aefee4ca22ae000803d974
😎 Deploy Preview https://deploy-preview-20804--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.

@BeryJu BeryJu changed the title fix(web): handle non-string values in formatUUID to prevent Event Log crash web/admin: handle non-string values in formatUUID to prevent Event Log crash Mar 9, 2026
@GirlBossRush GirlBossRush self-assigned this Mar 10, 2026
@GirlBossRush GirlBossRush added area:frontend Features or issues related to the browser, TypeScript, Node.js, etc backport/version-2026.2 Add this label to PRs to backport changes to version-2026.2 labels Mar 10, 2026
@BeryJu
Copy link
Member

BeryJu commented Mar 17, 2026

@tysoncung While the code change is valid, in which circumstance have you had event.context.device.pk be undefined or an integer?

@BeryJu BeryJu added the status/awaiting-contributor Awaiting a response from the contributor label Mar 17, 2026
@BeryJu
Copy link
Member

BeryJu commented Mar 20, 2026

For context, this can happen when a login_failed event is created with a failed webauthn validation, which passes device as-is into the context, which the frontend picks up like an endpoint device.

@BeryJu BeryJu added backport/version-2025.12 Add this label to PRs to backport changes to version-2025.12 and removed status/awaiting-contributor Awaiting a response from the contributor labels Mar 20, 2026
@codecov
Copy link

codecov bot commented Mar 20, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.40%. Comparing base (a72849e) to head (d692cbc).
⚠️ Report is 155 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #20804      +/-   ##
==========================================
- Coverage   93.44%   93.40%   -0.05%     
==========================================
  Files         992      992              
  Lines       55876    55876              
==========================================
- Hits        52213    52189      -24     
- Misses       3663     3687      +24     
Flag Coverage Δ
conformance 37.59% <ø> (+<0.01%) ⬆️
e2e 43.11% <ø> (-0.01%) ⬇️
integration 22.27% <ø> (-0.05%) ⬇️
unit 91.60% <ø> (+<0.01%) ⬆️
unit-migrate 91.69% <ø> (+<0.01%) ⬆️

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

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

@BeryJu BeryJu merged commit 82111d7 into goauthentik:main Mar 20, 2026
103 of 105 checks passed
authentik-automation bot pushed a commit that referenced this pull request Mar 20, 2026
…g crash (#20804)

fix(web): handle non-string values in formatUUID to prevent Event Log crash

When event context contains a device with a non-string pk value,
formatUUID crashes with TypeError: s.substring is not a function,
preventing the entire Event Log page from loading.

Add a type guard to coerce non-string values to their string
representation instead of crashing.

Fixes #20803
@authentik-automation
Copy link
Contributor

🍒 Cherry-pick to version-2025.12 created: #21051

authentik-automation bot pushed a commit that referenced this pull request Mar 20, 2026
…g crash (#20804)

fix(web): handle non-string values in formatUUID to prevent Event Log crash

When event context contains a device with a non-string pk value,
formatUUID crashes with TypeError: s.substring is not a function,
preventing the entire Event Log page from loading.

Add a type guard to coerce non-string values to their string
representation instead of crashing.

Fixes #20803
@authentik-automation
Copy link
Contributor

🍒 Cherry-pick to version-2026.2 created: #21052

BeryJu pushed a commit that referenced this pull request Mar 20, 2026
…g crash (cherry-pick #20804 to version-2026.2) (#21052)

web/admin: handle non-string values in formatUUID to prevent Event Log crash (#20804)

fix(web): handle non-string values in formatUUID to prevent Event Log crash

When event context contains a device with a non-string pk value,
formatUUID crashes with TypeError: s.substring is not a function,
preventing the entire Event Log page from loading.

Add a type guard to coerce non-string values to their string
representation instead of crashing.

Fixes #20803

Co-authored-by: Tyson Cung <45380903+tysoncung@users.noreply.github.com>
BeryJu pushed a commit that referenced this pull request Mar 20, 2026
…g crash (cherry-pick #20804 to version-2025.12) (#21051)

web/admin: handle non-string values in formatUUID to prevent Event Log crash (#20804)

fix(web): handle non-string values in formatUUID to prevent Event Log crash

When event context contains a device with a non-string pk value,
formatUUID crashes with TypeError: s.substring is not a function,
preventing the entire Event Log page from loading.

Add a type guard to coerce non-string values to their string
representation instead of crashing.

Fixes #20803

Co-authored-by: Tyson Cung <45380903+tysoncung@users.noreply.github.com>
kensternberg-authentik added a commit that referenced this pull request Mar 24, 2026
* main: (41 commits)
  ci: rotate GH App private key (#21085)
  internal/web: remove authentication for metrics (#21077)
  lib/config: explicit some defaults (#21079)
  internal: remove unix sockets on shutdown (#21081)
  ci: fix escaping in cherry-pick action (#21082)
  lib/config: support printing multiple values (#21080)
  root: fix rust setup (#21078)
  core: bump types-docker from 7.1.0.20260109 to 7.1.0.20260322 (#21062)
  policies: remove BufferedPolicyAccessView leftovers (#21057)
  core: bump axllent/mailpit from v1.29.3 to v1.29.4 in /tests/e2e (#21061)
  core: bump types-channels from 4.3.0.20250822 to 4.3.0.20260321 (#21063)
  core: bump github.com/jackc/pgx/v5 from 5.8.0 to 5.9.1 (#21059)
  translate: Updates for project authentik and language fr_FR (#21056)
  ci: bump taiki-e/install-action from 2.69.2 to 2.69.6 in /.github/actions/setup (#21068)
  web: bump the storybook group across 1 directory with 5 updates (#21031)
  web: bump knip from 5.88.0 to 5.88.1 in /web (#21033)
  web: bump type-fest from 5.4.4 to 5.5.0 in /web (#21032)
  events: prevent exception when events contains incompatible unicode (#21048)
  web/admin: handle non-string values in formatUUID to prevent Event Log crash (#20804)
  events: avoid implicitly setting context from login_failed event (#21045)
  ...
kensternberg-authentik added a commit that referenced this pull request Mar 26, 2026
* main: (22 commits)
  ci: rotate GH App private key (#21085)
  internal/web: remove authentication for metrics (#21077)
  lib/config: explicit some defaults (#21079)
  internal: remove unix sockets on shutdown (#21081)
  ci: fix escaping in cherry-pick action (#21082)
  lib/config: support printing multiple values (#21080)
  root: fix rust setup (#21078)
  core: bump types-docker from 7.1.0.20260109 to 7.1.0.20260322 (#21062)
  policies: remove BufferedPolicyAccessView leftovers (#21057)
  core: bump axllent/mailpit from v1.29.3 to v1.29.4 in /tests/e2e (#21061)
  core: bump types-channels from 4.3.0.20250822 to 4.3.0.20260321 (#21063)
  core: bump github.com/jackc/pgx/v5 from 5.8.0 to 5.9.1 (#21059)
  translate: Updates for project authentik and language fr_FR (#21056)
  ci: bump taiki-e/install-action from 2.69.2 to 2.69.6 in /.github/actions/setup (#21068)
  web: bump the storybook group across 1 directory with 5 updates (#21031)
  web: bump knip from 5.88.0 to 5.88.1 in /web (#21033)
  web: bump type-fest from 5.4.4 to 5.5.0 in /web (#21032)
  events: prevent exception when events contains incompatible unicode (#21048)
  web/admin: handle non-string values in formatUUID to prevent Event Log crash (#20804)
  events: avoid implicitly setting context from login_failed event (#21045)
  ...
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-2025.12 Add this label to PRs to backport changes to version-2025.12 backport/version-2026.2 Add this label to PRs to backport changes to version-2026.2

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Event logs fail to load with TypeError: s.substring is not a function

3 participants