Skip to content

feat(java): detect content-security-policy response header set to an empty value on a served entrypoint (CWE-693/79) - #156

Open
ai-anant wants to merge 3 commits into
CodeVigilant:mainfrom
ai-anant:rule/java-jenkins-empty-csp-response-header
Open

feat(java): detect content-security-policy response header set to an empty value on a served entrypoint (CWE-693/79)#156
ai-anant wants to merge 3 commits into
CodeVigilant:mainfrom
ai-anant:rule/java-jenkins-empty-csp-response-header

Conversation

@ai-anant

Copy link
Copy Markdown

Adds a Java/Jenkins rule that flags an HTTP response handler (Stapler setHeader/setContentSecurityPolicy) which assigns an empty string to the Content-Security-Policy response header while serving an active document (HTML/JS/SVG entrypoint).

Why it matters

When a server serves active content whose body embeds data outside the developer's direct control (report/artifact output, user-uploaded content), omitting an effective CSP lets any script in that content execute with full application-origin privileges. The robust pattern is to set a strict sandbox ...; script-src ... policy (or serve from an isolated origin) on the entrypoint, never an empty value.

Rule

  • New path: java/jenkins/xss/empty-csp-response-entrypoint.yaml
  • Severity: WARNING, languages: [java]
  • Detects: setHeader("Content-Security-Policy", ""), setHeader(<content-security header var>, ""), setContentSecurityPolicy("")

Validated with semgrep --validate and manually tested against a positive repro (empty CSP set then active document served — fires) and a sanitized negative (non-empty sandbox CSP — does not fire).

Closest existing open rules differ: rule/html-missing-csp-meta (PR #133) targets static HTML files missing a CSP meta tag; this rule targets the Java server-side response-header sink that empties an otherwise-effective policy.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant