Judge server templates: inline scripts, template code and Node views - #27
Merged
Merged
Conversation
JevGate never read server templates, and they held most of the documented vulnerabilities it missed in the intentionally vulnerable apps. - An ERB, EJS, JSP, Handlebars, Mustache, Nunjucks, Twig, Jinja or Go template, or HTML under templates/, views/, layouts/, partials/ or includes/, is parsed as its inline scripts with its tags blanked, and its top-level script is judged like a PHP page script. Its requests say the code runs in the visitor's browser. - Its `template code` is one more unit: tags that write request, cookie, session or signed-in-user data unescaped (judged by injection), and every scriptlet and declaration of a JSP page once one reads the request (judged by every security rule). - A Node handler that renders a view by name is sent the view's unescaped lines, as Django views are, and its questions name such templates. A template holding neither inline scripts nor template code is not selected. On the corpus, 24 documented vulnerabilities are found that no rule read (RailsGoat's and DVNA's XSS, DVGA's paste-page XSS, DVJA's JSP XSS, JavaVulnerableLab's JSP-only injections, traversal, SSRF and leaked stack traces); 42 of 49 labeled reviews and 16 of 25 considers in templates were right. Requests outside templates and render calls are unchanged on the other 101 projects.
…check's help
Pug writes a value unescaped with `!=` right after a tag or at the start of
a line, and with `!{…}`; `err.name !== 'AbortError'` in a view's script
is a comparison. hackathon-starter's handlers were sent such comparisons as
unescaped output. `check --help` names the component and server template
files JevGate selects.
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.
Stacked on #26. JevGate never read server templates, and they held most of the vulnerabilities the audit's vulnerable apps document that it missed. This teaches it three things about them.
What changes
templates/,views/,layouts/,partials/orincludes/, is parsed as its<script>code, with its template tags blanked so lines stay the file's. Its top-level script is judged like a PHP page script by every security rule, and its requests say the code runs in the visitor's browser.template code. For ERB, EJS, Handlebars, Jinja and Twig that is the tags writing such a value unescaped; injection judges them. For JSP it is every scriptlet and declaration once one reads the request; every security rule judges them.res.render('app/products', …)) is sent the view's lines that write values unescaped, as Django views already were. Its presence question, markup check and markup Choice name such templates.A template holding neither inline scripts nor template code is not selected; 900 of the corpus's 1,003 templates stay out of reports.
Results
Documented vulnerabilities in the intentionally vulnerable apps that no rule read, now found (24):
location.hashintodocument.write) and Write findings as SARIF for code scanning #11 (raw cookies[:font]) are reviews; Print shell completions and man pages #9 (first_name.html_safe) is a consider.<%- %>) is a review; Print shell completions and man pages #9 and Color agent output on a terminal #10 are considers.<%= request.getParameter(...) %>, as a review.Held-out projects: 1 review right (dvja), 1 consider wrong (mdbook's page script). Corpus cost of the whole branch: about $0.1.
Sanity check on four real apps outside the corpus, template paths only (about $0.07):
raw fullstory_script(current_user: …), whose helper writes the user's email unescaped into a<script>string. That is a real, if self-only, injection. It also got a hard-coded production sign-in URL in a page script.!=rule also matched!==comparisons, now fixed. What remains aretd!= link(scraped HTML) and!{ publicKey }JSON in a script tag.Review notes
visit. CI's review runs the released 0.20.0, which also flagssettle.rs(fixed by Audit 0.20.0 on 103 projects: crash and hang fixes, security checks, precision caps #26's file-organization change).check --helpnow names component and server template files.