Fix CSP blocking inline translations and broken routes.py#6
Merged
Conversation
…#5 followup) The i18n PR (#5) introduced two bugs: (1) broken indentation in _template_response() causing SyntaxError at import, and (2) an inline <script> violating script-src 'self' CSP policy. Fixes: - Re-indent lines 100-107 of routes.py back inside _template_response() - Add per-request CSP nonce via secrets.token_urlsafe() in middleware - Add nonce attribute to inline translations <script> in base.html - Add rate limiter reset fixture to prevent 429 cascade across tests - Add tests verifying nonce presence, uniqueness, and header/HTML match
Contributor
Greptile SummaryThis PR delivers three targeted fixes introduced by the i18n PR (#5): a Key changes:
One minor style nit: Confidence Score: 5/5
Important Files Changed
Sequence DiagramsequenceDiagram
participant Browser
participant SecurityMiddleware
participant RouteHandler
participant Jinja2Template
Browser->>SecurityMiddleware: GET /
SecurityMiddleware->>SecurityMiddleware: nonce = secrets.token_urlsafe(16)
SecurityMiddleware->>SecurityMiddleware: request.state.csp_nonce = nonce
SecurityMiddleware->>RouteHandler: call_next(request)
RouteHandler->>RouteHandler: read csp_nonce from request.state
RouteHandler->>Jinja2Template: render index.html with csp_nonce + translations_json
Jinja2Template-->>RouteHandler: HTML with script nonce attribute set
RouteHandler-->>SecurityMiddleware: HTMLResponse
SecurityMiddleware->>SecurityMiddleware: Set CSP header with nonce in script-src
SecurityMiddleware-->>Browser: Response with CSP header and HTML body
Reviews (1): Last reviewed commit: "Fix CSP blocking inline translations and..." | Re-trigger Greptile |
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
routes.py— the i18n PR (Add i18n support for web UI (German + English) #5) left lines 100-107 at column 0 (module level), breaking the_template_response()function and preventing the app from startingsecrets.token_urlsafe) toscript-srcdirective and to the inline<script>tag that loads translations intowindow.__translationsTest plan
make checkpasses (lint + mypy strict + 265 tests, 96.53% coverage)window.__t("key")returns translated text