Skip to content

feat: audit event session attribution - #3422

Merged
tada5hi merged 11 commits into
masterfrom
feat/event-session-id
Aug 10, 2026
Merged

tada5hi merged 11 commits into
masterfrom
feat/event-session-id

Conversation

@tada5hi

@tada5hi tada5hi commented Aug 10, 2026 •

Copy link
Copy Markdown
Collaborator

What

Adds session attribution to the security event log: auth_events gains a session_id column naming the auth_sessions row that performed or is affected by each event, queryable via filter[sessionId] and surfaced in the admin console.

How

  • Column + migration (EventSessionId1786320000000, both dialects): nullable, indexed, deliberately FK-less. The audit table is append-only and sessions are routinely deleted; a CASCADE would erase audit history and SET NULL would destroy the correlation. NULL means not attributable to a session (pre-migration rows, failed logins, registration, password recovery, the unauthenticated external IdP callback).
  • Write path, two mechanisms: the request-context snapshot (AsyncLocalStorage) now carries the bearer's session id, so the entity-CRUD bridge and the key / trust-anchor / identity-provider-account / user-authenticator emits inherit it; the OAuth2/MFA sites stamp explicitly where the session is created or referenced mid-request (password-grant and mfa-login LOGIN, AUTHORIZE(_FAILED) via the threaded bearer session, LOGOUT with the revoked session, REFRESH_REPLAY_DETECTED, challenge verify incl. the MFA ticket's pending session).
  • Cleanup: LOGIN no longer duplicates the id into data.sessionId and LOGOUT drops data.revokedSessionId; the sanitizer allowlist follows. Old rows age out via retention (no backfill).
  • Read path: sessionId joins the event schema fields/filters allow-lists; the existing EVENT_READ gating applies unchanged (session ids were already reachable via refId on session-scoped events, so this uniformizes rather than widens exposure).
  • Admin console: /sessions/:id gains an events section (gated on EVENT_READ) next to the token inventory; /events/:id links the session id.
  • Bug fix along the way: identity-provider link/unlink events persisted data: null because providerId/providerName were never in the sanitizer allowlist; both keys are now allowlisted, matching the documented plan-091 behavior.

Verification

  • Full monorepo build and server-core suite green (186 files / 2074 tests), including a new end-to-end test proving a bearer-authenticated entity write attributes the acting session through the request-context path.
  • Migration run, revert, run verified against mysql and postgres.
  • .agents/architecture.md Security Event Log section updated.

Summary by CodeRabbit

  • New Features
    • Security events now record their associated session when available.
    • Events can be filtered by session ID for easier investigation.
    • Event details link directly to the associated session.
    • Session details now include a paginated list of related events, including event type, scope, actor, IP address, and creation time.
  • Improvements
    • Login, logout, OAuth2, MFA, and security lifecycle events now provide more consistent session tracking.
    • Events without session information display a clear fallback.

tada5hi added 11 commits August 10, 2026 12:15
…vent data-key allowlist

Add a bearer-token end-to-end test to the entity-CRUD audit bridge spec: a
user logs in via the password grant, creates a role with its own bearer, and
the resulting entity event must carry the session id the login row names. This
covers the AsyncLocalStorage request-context path from the authorization
middleware through to the persisted column.

Drop sessionId and revokedSessionId from the event data-key allowlist. No emit
site writes either into the data bag anymore; a session id rides the dedicated
sessionId column. The sanitize spec now pins that both keys are dropped.

Assert the two service stamps that went unchecked: the trust-anchor spec feeds
a real session id through its fake request context, and the identity-provider
account spec wires an event service plus request context so the unlink event's
session attribution is covered.
Copilot AI lite review requested due to automatic review settings August 10, 2026 11:55

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@coderabbitai

coderabbitai Bot commented Aug 10, 2026 •

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 651d59bb-a270-456c-86e8-8dfe2f8db000

📥 Commits

Reviewing files that changed from the base of the PR and between 776239d and 9b8e87d.

📒 Files selected for processing (37)
  • .agents/architecture.md
  • apps/client-admin-console/pages/events/[id]/index.vue
  • apps/client-admin-console/pages/sessions/[id]/index.vue
  • apps/server-core/src/adapters/database/domains/event/entity.ts
  • apps/server-core/src/adapters/database/migrations/mysql/1786320000000-EventSessionId.ts
  • apps/server-core/src/adapters/database/migrations/postgres/1786320000000-EventSessionId.ts
  • apps/server-core/src/adapters/http/controllers/workflows/authenticator-challenge/module.ts
  • apps/server-core/src/adapters/http/request/event-context.ts
  • apps/server-core/src/app/modules/http/modules/controller.ts
  • apps/server-core/src/core/entities/event/entity-event-handler.ts
  • apps/server-core/src/core/entities/event/sanitize.ts
  • apps/server-core/src/core/entities/event/schema.ts
  • apps/server-core/src/core/entities/event/service.ts
  • apps/server-core/src/core/entities/event/types.ts
  • apps/server-core/src/core/entities/identity-provider-account/service.ts
  • apps/server-core/src/core/entities/key/service.ts
  • apps/server-core/src/core/entities/trust-anchor/service.ts
  • apps/server-core/src/core/entities/user-authenticator/service.ts
  • apps/server-core/src/core/entities/user-authenticator/types.ts
  • apps/server-core/src/core/oauth2/authorization/module.ts
  • apps/server-core/src/core/oauth2/end-session/service.ts
  • apps/server-core/src/core/oauth2/grant-types/password.ts
  • apps/server-core/src/core/oauth2/grant-types/refresh-token.ts
  • apps/server-core/src/core/oauth2/mfa-login/module.ts
  • apps/server-core/test/unit/core/entities/event/entity-event-handler.spec.ts
  • apps/server-core/test/unit/core/entities/event/sanitize.spec.ts
  • apps/server-core/test/unit/core/entities/event/service.spec.ts
  • apps/server-core/test/unit/core/entities/identity-provider-account/service.spec.ts
  • apps/server-core/test/unit/core/entities/key/service.spec.ts
  • apps/server-core/test/unit/core/entities/trust-anchor/service.spec.ts
  • apps/server-core/test/unit/core/entities/user-authenticator/service.spec.ts
  • apps/server-core/test/unit/core/oauth2/authorization/module.spec.ts
  • apps/server-core/test/unit/core/oauth2/end-session/service.spec.ts
  • apps/server-core/test/unit/core/oauth2/grant-types/refresh-token.spec.ts
  • apps/server-core/test/unit/http/controllers/entities/event-entity-bridge.spec.ts
  • apps/server-core/test/unit/http/controllers/entities/event.spec.ts
  • packages/core-kit/src/domains/event/entity.ts

📝 Walkthrough

Walkthrough

Security events now support nullable, indexed session attribution. Request, OAuth2, MFA, and audit flows populate session IDs. The events API filters by session ID, and the administration console links events and sessions.

Changes

Session-Attributed Security Events

Layer / File(s) Summary
Event contract and storage
.agents/architecture.md, apps/server-core/src/core/entities/event/*, apps/server-core/src/adapters/database/..., packages/core-kit/src/domains/event/entity.ts
Event contracts and persistence now support nullable indexed sessionId values. Event filtering and sanitization rules were updated.
Session context propagation
apps/server-core/src/adapters/http/..., apps/server-core/src/core/entities/..., apps/server-core/src/core/oauth2/...
Request context, entity audits, authenticator flows, authorization, login, refresh replay, and logout events now record session IDs.
Event query and administration views
apps/client-admin-console/pages/events/[id]/index.vue, apps/client-admin-console/pages/sessions/[id]/index.vue
Event details link to sessions. Session details show permission-gated, paginated events filtered by session ID.
Session attribution validation
apps/server-core/test/unit/...
Tests cover propagation, null defaults, top-level session fields, event filtering, projection, and audit records.

Estimated code review effort: 4 (Complex) | ~45 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Request
  participant AuthenticationFlow
  participant EventService
  participant EventsAPI
  participant AdminConsole
  Request->>AuthenticationFlow: provide sessionId
  AuthenticationFlow->>EventService: record security event with sessionId
  EventService->>EventsAPI: persist and expose sessionId
  AdminConsole->>EventsAPI: filter events by sessionId
  EventsAPI-->>AdminConsole: return session-attributed events
Loading

Possibly related PRs

  • authup/authup#3187: Adds session ID storage and bearer-session propagation used by event attribution.
  • authup/authup#3229: Modifies the same security event system extended here with session attribution.
  • authup/authup#3235: Shares MFA challenge and UserAuthenticatorService session-context changes.
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 20.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the primary change: adding session attribution to audit events.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/event-session-id

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

ESLint install timed out. The project may have too many dependencies for the sandbox.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@pkg-pr-new

pkg-pr-new Bot commented Aug 10, 2026

Copy link
Copy Markdown

Open in StackBlitz

authup

npm i https://pkg.pr.new/authup@3422

@authup/client-account-console

npm i https://pkg.pr.new/@authup/client-account-console@3422

@authup/client-admin-console

npm i https://pkg.pr.new/@authup/client-admin-console@3422

@authup/client-auth-console

npm i https://pkg.pr.new/@authup/client-auth-console@3422

@authup/server-core

npm i https://pkg.pr.new/@authup/server-core@3422

@authup/access

npm i https://pkg.pr.new/@authup/access@3422

@authup/client-web-kit

npm i https://pkg.pr.new/@authup/client-web-kit@3422

@authup/client-web-kit-theme

npm i https://pkg.pr.new/@authup/client-web-kit-theme@3422

@authup/client-web-nuxt

npm i https://pkg.pr.new/@authup/client-web-nuxt@3422

@authup/client-web-theme

npm i https://pkg.pr.new/@authup/client-web-theme@3422

@authup/core-http-kit

npm i https://pkg.pr.new/@authup/core-http-kit@3422

@authup/core-kit

npm i https://pkg.pr.new/@authup/core-kit@3422

@authup/core-realtime-kit

npm i https://pkg.pr.new/@authup/core-realtime-kit@3422

@authup/errors

npm i https://pkg.pr.new/@authup/errors@3422

@authup/i18n

npm i https://pkg.pr.new/@authup/i18n@3422

@authup/kit

npm i https://pkg.pr.new/@authup/kit@3422

@authup/server-adapter-kit

npm i https://pkg.pr.new/@authup/server-adapter-kit@3422

@authup/server-adapter-node

npm i https://pkg.pr.new/@authup/server-adapter-node@3422

@authup/server-adapter-socket-io

npm i https://pkg.pr.new/@authup/server-adapter-socket-io@3422

@authup/server-adapter-web

npm i https://pkg.pr.new/@authup/server-adapter-web@3422

@authup/server-kit

npm i https://pkg.pr.new/@authup/server-kit@3422

@authup/server-test-kit

npm i https://pkg.pr.new/@authup/server-test-kit@3422

@authup/specs

npm i https://pkg.pr.new/@authup/specs@3422

commit: 9b8e87d

@tada5hi
tada5hi merged commit 6d7759b into master Aug 10, 2026
13 checks passed
@tada5hi
tada5hi deleted the feat/event-session-id branch August 10, 2026 12:04
@github-actions github-actions Bot mentioned this pull request Aug 10, 2026
@github-actions github-actions Bot mentioned this pull request Aug 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants