feat(java): detect unescaped raw() of non-literal values in Groovy/Stapler view templates (CWE-79) - #155
Open
ai-anant wants to merge 1 commit into
Conversation
…apler view templates (CWE-79)
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.
Adds a rule (rule id
codevigilant.java.jenkins.view.raw-unescaped-output) that flags Groovy/Stapler view templates which pass a non-literal value to theraw(...)output builder.The Jenkins
raw(...)builder writes its argument to the HTTP response verbatim, skipping all HTML/XML escaping. When the argument is a model getter, changelog/SCM-derived value, or any external/request-derived string, an attacker who controls that value can inject arbitrary markup/script into the rendered page (stored/reflected XSS, CWE-79). The pattern is:Because Groovy view templates are
.groovyfiles and there is no native semgrepgroovylanguage, the rule is declared withlanguages: [generic]so it is applied to.groovyfiles during a normal repo sweep (ajava-language rule scans 0.groovytargets, verified). Constant string literals passed throughraw("...")are excluded viapattern-not, keeping the rule focused on tainted/non-literal output.Validation + tests:
semgrep --validate --config java/: valid (118 rules total with php/).testcases/java/jenkins/view/raw-unescaped-output-pos.groovyfires (4/4):raw(c.msgAnnotated),raw(c.getCommitId()),raw(browser.getChangeSetLink(c)),raw(entry.msg).testcases/java/jenkins/view/raw-unescaped-output-neg.groovyis clean (0): constantraw("...")literals, andtext(...)/ builder paths.Severity HIGH, confidence MEDIUM (generic-mode matcher may also flag a
raw("constant")if a comment or string contains theraw(token sequence; the primary pattern-not strips the dominant false-positive class).