Security patches#17
Merged
Merged
Conversation
There was a problem hiding this comment.
Pull request overview
This PR applies a set of security-focused improvements across the API, auth flow, and UI, including OAuth CSRF-state validation, basic API rate limiting, and safer DOM rendering for user history.
Changes:
- Add
slowapi-based rate limiting to/api/detectand tighten request/query validation (max text length; boundedlimit/offset). - Harden GitHub OAuth callback by generating/verifying a per-login
statevalue stored in an HTTP-only cookie. - Prevent XSS in the UI history list by replacing
innerHTMLtemplating with DOM node creation (textContent).
Reviewed changes
Copilot reviewed 5 out of 6 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
uv.lock |
Locks new dependency set for slowapi and transitive packages (limits, deprecated, wrapt). |
pyproject.toml |
Adds slowapi>=0.1.9 to runtime dependencies. |
app/main.py |
Configures SlowAPI limiter/handler; adds request size limit; rate-limits /api/detect; validates results pagination params. |
app/routes/auth.py |
Adds OAuth state generation + cookie storage and constant-time verification on callback; clears cookie after success. |
app/static/index.html |
Reworks history rendering to avoid innerHTML injection risk. |
tests/conftest.py |
Updates mocked detector output to include newly expected entropy metrics; adjusts import suppression. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
13
to
+17
| from fastapi.testclient import TestClient | ||
| from sqlalchemy import create_engine | ||
| from sqlalchemy.orm import sessionmaker | ||
|
|
||
| from app.database import Base, get_db | ||
|
|
||
|
|
||
| from app.database import Base, get_db # noqa: E402 |
Comment on lines
68
to
74
| @router.get("/callback") | ||
| async def oauth_callback( | ||
| code: str = Query(...), | ||
| state: str = Query(...), | ||
| request: Request = None, | ||
| db: Session = Depends(get_db), | ||
| ): |
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.
No description provided.