fix(security): escape template outputs and add template security tests#356
Open
Viraj0711 wants to merge 1 commit into
Open
fix(security): escape template outputs and add template security tests#356Viraj0711 wants to merge 1 commit into
Viraj0711 wants to merge 1 commit into
Conversation
|
@Viraj0711 is attempting to deploy a commit to the komalsony234-1530's projects Team on Vercel. A member of the Team first needs to authorize it. |
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.
Branch:
security/sanitize-templatesSummary
This PR hardens server-side templates against XSS by escaping data injected into HTML and safely serializing values used in JavaScript. It also adds unit tests that render templates with malicious inputs to prevent regressions.
Related Issue
Closes: #355
Type of Change
What Was Changed
templates/project.htmltojsonforPROJECT_ID. Cleaned class names for badges.tests/test_security.pyproject.htmlwith malicious inputs and asserts content is escaped.tests/test_index_security.pyindex.htmlwith maliciousstatsand asserts escaping.How to Test This PR
git checkout security/sanitize-templatespip install -r requirements.txtpython -m pytest -qExpected test output (relevant lines):
Test Results
(Include CI output or paste results after running locally.)
Self-Review Checklist
|safeand uncontrolled HTML rendering.tojson.Notes for Reviewer
classnames are derived from data (e.g.,badge--{{ project.level | lower }}) to ensure they can't break markup — this PR normalizes spaces to hyphens for safety.bleachif any HTML should be allowed in data fields, and (b) scan client-side code (static/script.js) for unsafe DOM APIs (innerHTML,eval,document.write).Suggested commit message
You can copy-paste the Issue content above into a new GitHub Issue and the PR content into your PR description. If you want, I can also:
bleachand an example of a sanitized allowlist for fields that require HTML.Which would you like next?