refactor(server): scope skew-protection exemption to login form#10164
Merged
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Contributor
There was a problem hiding this comment.
Pull request overview
This PR narrows the SkewProtectionMiddleware exemption so that only the server-rendered login form POST (/auth/login) is allowed to submit without the Marimo-Server-Token header, rather than exempting all application/x-www-form-urlencoded requests. It also adds tests to ensure skew protection is enforced for form-encoded requests while still allowing the login form to function.
Changes:
- Refactor skew-protection exemption logic to key off the
/auth/loginpath instead of Content-Type. - Add test coverage confirming form-urlencoded requests still require a valid skew token.
- Add a test confirming
/auth/loginPOST is not gated by skew protection.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
marimo/_server/api/middleware.py |
Replaces the Content-Type-based exemption with a path-based exemption for /auth/login. |
tests/_server/api/test_middleware.py |
Adds tests covering skew token enforcement for form content types and exemption for the login form POST. |
Comment on lines
+171
to
+178
| response = client.post( | ||
| "/api/home/running_notebooks", | ||
| headers={ | ||
| **token_header("fake-token", "old-skew-id"), | ||
| "Content-Type": "application/x-www-form-urlencoded", | ||
| }, | ||
| content=json.dumps({}), | ||
| ) |
Comment on lines
+182
to
+189
| response = client.post( | ||
| "/api/home/running_notebooks", | ||
| headers={ | ||
| **token_header("fake-token"), | ||
| "Content-Type": "application/x-www-form-urlencoded", | ||
| }, | ||
| content=json.dumps({}), | ||
| ) |
Comment on lines
+205
to
+207
| assert response.status_code != 401, ( | ||
| "skew protection should not gate /auth/login" | ||
| ) |
Comment on lines
+133
to
+135
| # If the login form submission, then skip. | ||
| # The login page is a server-rendered plain HTML form and does not | ||
| # attach the server token header. |
Contributor
There was a problem hiding this comment.
No issues found across 2 files
Architecture diagram
sequenceDiagram
participant Client as HTTP Client
participant Middleware as SkewProtectionMiddleware
participant App as Application
Note over Client,App: POST requests to server
Client->>Middleware: POST /auth/login (no skew token)
Middleware->>Middleware: Check request method (POST)
Middleware->>Middleware: Path ends with "/auth/login"? → Yes
Middleware->>App: Pass through (exempted)
App-->>Client: Login page response
Client->>Middleware: POST /api/other (form‑encoded, no valid token)
Middleware->>Middleware: Check request method (POST)
Middleware->>Middleware: Path is exempt? → No
Middleware->>Middleware: Path is /api/kernel/execute? → No
Middleware->>Middleware: Validate skew token header
alt Valid token present
Middleware->>App: Pass through
App-->>Client: Normal response
else Token invalid or missing
Middleware-->>Client: 401 Unauthorized
end
Only the server-rendered login form legitimately posts without the server token, so exempt it by path instead of by Content-Type. Adds tests covering the login exemption and token enforcement for form-encoded requests.
mscolnick
force-pushed
the
ms/skew-protection-login-exemption
branch
from
July 15, 2026 15:38
4df243a to
ff10d74
Compare
dmadisetti
approved these changes
Jul 16, 2026
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.
Only the server-rendered login form legitimately posts without the
server token, so exempt it by path instead of by Content-Type. Adds
tests covering the login exemption and token enforcement for
form-encoded requests.