Skip to content

fix: never assume an unreadable template file escapes - #179

Merged
SizzleUnrlsd merged 2 commits into
mainfrom
fix/unreadable-template-not-escaped
Sep 28, 2026
Merged

SizzleUnrlsd merged 2 commits into
mainfrom
fix/unreadable-template-not-escaped

Conversation

@SizzleUnrlsd

Copy link
Copy Markdown
Contributor

Summary

escaped_templates read a template file it could not open (permissions) as empty text, and an empty template escapes everything it renders, so the flow through render_to_string was dropped as safe. Such a file now yields no escaping verdict, like a template the analyzer cannot find: the flow stays xss, and a template extending or including the unreadable one is not established to escape either. The unreadable file was already listed among the templates the run could not read (0.16.0), so the VEX side was right; the XSS judgement was not.

Out of scope, on purpose: an unreadable Python file still counts as setting no autoescape = False. It is reported as unreadable in the coverage, and the escaping rule's other conditions are about templates; say so if you want it to disable the judgement too.

Verification

  • RED: 4 failures, the template judged escaped and no xss.
  • tests/test_unreadable_templates.py: 4 passed (skipped as root or off POSIX, where a file cannot be made unreadable). Targeted template tests and docs tests pass; full suite under Python 3.12.10: 1438 passed. ruff check and mypy pass.

A template file the engine cannot read proves nothing about escaping: the flow through render_to_string stays xss, and a template extending or including it is not established to escape either.
escaped_templates read a template file it could not open as empty text, and an empty template escapes everything it renders. Such a file now yields no escaping verdict, like a template the engine cannot find, so the flow stays xss and the templates needing it are not established either.
@SizzleUnrlsd SizzleUnrlsd added the bug Something isn't working label Sep 28, 2026
@SizzleUnrlsd SizzleUnrlsd self-assigned this Sep 28, 2026
@SizzleUnrlsd
SizzleUnrlsd merged commit 0bf5884 into main Sep 28, 2026
10 checks passed
@SizzleUnrlsd
SizzleUnrlsd deleted the fix/unreadable-template-not-escaped branch September 28, 2026 17:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant