docs: clarify pre-authentication action CSRF#2
Merged
Conversation
There was a problem hiding this comment.
Pull request overview
This PR clarifies and codifies the framework’s CSRF contract for page actions: CSRF tokens are tied to an application-owned session identity and the framework will not implicitly mint/persist anonymous sessions for pre-authentication flows.
Changes:
- Adds documentation explaining that anonymous pages receive no CSRF token by default and submissions are rejected with 403 unless a stable session identity is provided.
- Extracts
ActionRegistryOptionsinto a dedicated module and re-exports it for consumers. - Adds regression tests covering (1) anonymous rejection when no session identity exists and (2) a guest/pre-auth session identity provided via middleware.
Reviewed changes
Copilot reviewed 5 out of 6 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| tests/actions.test.ts | Adds regression tests for anonymous CSRF rejection and custom pre-auth guest session support. |
| src/askr/actions.ts | Moves ActionRegistryOptions type out to a separate module and re-exports it. |
| src/askr/action-options.ts | New, documented home for ActionRegistryOptions, clarifying the CSRF/session identity contract. |
| README.md | Documents the default csrf.sessionId behavior and provides a safe pre-auth session wiring example. |
| package.json | Bumps package version to 0.0.7. |
| package-lock.json | Updates lockfile version fields to 0.0.7. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
ActionRegistryOptions.csrfandsessionIdthat anonymous pages receive no token and submissions return 403 when the resolver returnsundefined@askrjs/[email protected]Decision
This keeps the existing security boundary: the framework signs tokens against an application-owned session identity but does not silently mint or persist anonymous sessions. Session lifetime, cookie policy, rotation, and storage belong to the application/session layer. The newly explicit contract makes login, signup, and password-reset setup discoverable without weakening CSRF behavior.
Verification
npm run checkCloses #1