feat: harden study auth redirects#74
Conversation
## Internal ### Updates & Improvements * Magic-link generation sanitizes and URL-encodes redirect query parameters.
|
Warning Rate limit exceeded
Your organization is not enrolled in usage-based pricing. Contact your admin to enable usage-based pricing to continue reviews beyond the rate limit, or try again in 3 minutes and 17 seconds. ⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
|
Claude encountered an error —— View job I'll analyze this and get back to you. |
|
| Filename | Overview |
|---|---|
| pingpong/auth.py | Adds normalize_study_redirect with multi-layered open-redirect prevention (prefix checks, control-char filter, urlsplit scheme/netloc guard) and switches to urlencode for safe query-string construction in magic links. |
| pingpong/study/server.py | Applies normalize_study_redirect at all redirect-parameter ingestion points; introduces minor redundancy where normalization is called before generate_auth_link (which already normalizes internally). |
Flowchart
%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[Redirect input received] --> B{Is destination empty or None?}
B -- Yes --> Z[Return '/']
B -- No --> C[Strip whitespace]
C --> D{Starts with '/'?}
D -- No --> Z
D -- Yes --> E{Starts with '//' or backslash?}
E -- Yes --> Z
E -- No --> F{Contains control chars below 32?}
F -- Yes --> Z
F -- No --> G[Run urlsplit]
G --> H{Has scheme or netloc?}
H -- Yes --> Z
H -- No --> Y[Return sanitized path]
Reviews (1): Last reviewed commit: "feat: harden study auth redirects" | Re-trigger Greptile
| ) | ||
|
|
||
| nowfn = get_now_fn(request) | ||
| safe_forward = normalize_study_redirect(body.forward) |
There was a problem hiding this comment.
Redundant double normalization
normalize_study_redirect is called here on body.forward, then called a second time inside generate_auth_link (line 165 of auth.py). The same pattern repeats at line 209 for login_as. Since generate_auth_link already normalizes its redirect argument internally, the pre-call normalization in the server layer is redundant. It's harmless and serves as defense-in-depth, but it may cause confusion about where the canonical sanitization is expected to live. Consider either removing the pre-call normalization in server.py or removing it from inside generate_auth_link and documenting the expectation.
Internal
Updates & Improvements