Content Security Policy

CSP Nonce Bypasses: What CVE-2026-120421 Teaches Us About Trust Boundaries

CVE-2026-120421 shows why CSP nonces cannot replace safe output encoding. Learn how nonce trust boundaries fail and how to strengthen CSP deployments.

Content Security Policy nonces are one of the strongest tools available for controlling script execution in dynamic web applications. A server generates a fresh, unpredictable value for each response, places it in the CSP header and adds the same value to trusted script elements.

However, a nonce cannot make unsafe application code safe. CVE-2026-120421, a reflected cross-site scripting vulnerability in Eclipse Mojarra, is a useful reminder that CSP protection depends on the application preserving the boundary between trusted markup and untrusted input.

The vulnerability is not a break of the nonce generation algorithm. It is a framework-level issue that can cause attacker-controlled input to be inserted into a script context that already carries a valid nonce.

What happened in CVE-2026-120421?

CVE-2026-120421 affects certain Eclipse Mojarra versions when URL-based client window mode is enabled.

The affected versions are:

  • Mojarra 2.2.0 up to, but not including, 4.0.29
  • Mojarra 4.1.0 up to, but not including, 4.1.20
  • Mojarra 5.0.0-M1 up to, but not including, 5.0.0-M12

The issue involves the client window identifier supplied through request parameters such as jfwid or jakarta.faces.ClientWindow. In the affected code path, that value could be added to generated URLs without appropriate URL encoding.

When a component such as h:button rendered the value into a JavaScript string literal, an attacker could potentially inject JavaScript into the generated page. The vulnerability is classified as reflected XSS because the malicious input is supplied in a request and reflected into the response.

The CVE record states that the issue can also affect applications using Mojarra’s CSP nonce support. When com.sun.faces.enableCspNonce=true is enabled, injected content can be placed inside a nonce-bearing script element and execute when the page loads.

That distinction matters. The attacker is not guessing the nonce. The application is accidentally treating attacker-controlled data as part of a script element that the server has already marked as trusted.

Why a valid nonce does not guarantee safety

A nonce tells the browser that a particular script element was authorised by the server.

For example:

Content-Security-Policy:
  default-src 'self';
  script-src 'nonce-random-value-generated-for-this-response'

The server then includes the matching value in trusted script elements:

<script nonce="random-value-generated-for-this-response">
  initialiseApplication();
</script>

The browser compares the nonce in the element with the nonce in the policy. If they match, the script is allowed to execute.

This works well when the trusted script element contains only trusted code. It becomes dangerous when untrusted input is inserted into that same element or into a JavaScript string generated inside it.

The browser cannot determine which characters were written by the application developer and which came from a request parameter. It sees a script element with a valid nonce and follows the policy.

The security boundary has therefore shifted from:

Only scripts authorised by the server may execute

to:

Any content that the application places inside a server-authorised script element may execute

That is why nonce-based CSP must be combined with correct output encoding and safe framework behaviour.

This is not a cryptographic failure

It is tempting to describe this vulnerability as a nonce bypass, but that wording needs care.

CVE-2026-120421 does not mean that an attacker can calculate or predict a properly generated nonce. It does not show that the browser’s nonce comparison is broken. Instead, it demonstrates how an application can accidentally give attacker-controlled content the same trust as a legitimate script.

This is an application trust-boundary failure.

The nonce remains unpredictable, but the attacker does not need to know it if their input is incorporated into a script element that already has the valid nonce.

That distinction is useful when reviewing incidents. A CSP report that appears to involve a nonce does not automatically indicate weak randomness or nonce reuse. The cause may instead be:

  • unsafe interpolation into a trusted script block
  • incorrect HTML or JavaScript context encoding
  • a framework component that reflects request data
  • a template or rendering helper that assigns trusted markup too broadly
  • a proxy or middleware that changes the document after the policy is generated

The importance of context-aware output encoding

Encoding is not a single operation that can be applied everywhere.

The correct defence depends on the context in which data is inserted:

  • HTML text needs HTML encoding
  • HTML attributes need attribute encoding
  • JavaScript strings need JavaScript string escaping
  • URLs need URL encoding and validation
  • CSS values require CSS-aware handling
  • JSON embedded in HTML needs safe serialisation and correct delimiting

A value that is safe in ordinary HTML text may not be safe inside a JavaScript string. Likewise, URL encoding alone may not be sufficient if the resulting value is later inserted into an HTML or script context.

In the Mojarra case, the client window identifier was incorporated into generated URLs and JavaScript output. The application framework needed to preserve the correct encoding rules across each stage of that process.

This is one reason security reviews should trace data from its original source to its final browser context. Checking only the input validation function or only the final response header can miss the point where the trust boundary is crossed.

What CSP can and cannot do

A well-designed CSP can reduce the impact of many XSS vulnerabilities. A policy can:

  • block scripts loaded from unauthorised origins
  • prevent most inline scripts from executing
  • restrict inline event handlers
  • block dangerous string-to-code APIs such as eval when the policy does not permit 'unsafe-eval'
  • restrict where a document may be embedded
  • report attempted policy violations

A strict policy might include:

Content-Security-Policy:
  default-src 'self';
  object-src 'none';
  base-uri 'none';
  script-src 'nonce-{fresh-random-value}' 'strict-dynamic';
  frame-ancestors 'none';

However, CSP is not a replacement for output encoding. If attacker-controlled input is inserted into a script element that already has a valid nonce, the policy may consider the resulting element trusted.

MDN describes CSP as defence in depth, not as an alternative to sanitising and safely encoding input. That principle is especially important for nonce-based policies.

How CSP reporting can help

CSP reporting will not necessarily identify every successful exploit. If a malicious payload inherits a valid nonce inside a trusted script element, the browser may not generate a violation at all.

Reports are still valuable because they can reveal related activity and configuration problems, including:

  • blocked inline scripts
  • unexpected script sources
  • attempts to use javascript: URLs
  • blocked event handlers
  • policy differences between routes
  • missing directives on error pages or legacy views
  • browser-specific behaviour during an attack

A Report-Only policy can be used to collect evidence before enforcement:

Reporting-Endpoints:
  csp-endpoint="https://reports.example.com/csp"

Content-Security-Policy-Report-Only:
  default-src 'self';
  object-src 'none';
  base-uri 'none';
  script-src 'self' 'nonce-example';
  report-to csp-endpoint;
  report-uri https://reports.example.com/csp;

The report-to directive uses the endpoint declared in Reporting-Endpoints. The report-uri directive is retained here as a compatibility fallback for clients that do not support the newer Reporting API approach.

The nonce shown here is illustrative only. In production, the server must generate a fresh, unpredictable value for each response and insert the same value into the intended script elements.

A typical violation report may look like this:

{
  "type": "csp-violation",
  "age": 0,
  "url": "https://app.example.com/account",
  "user_agent": "ExampleBrowser/1.0",
  "body": {
    "documentURL": "https://app.example.com/account",
    "blockedURL": "inline",
    "violatedDirective": "script-src-elem",
    "effectiveDirective": "script-src",
    "originalPolicy": "default-src 'self'; object-src 'none'; base-uri 'none'; script-src 'self' 'nonce-example'",
    "sourceFile": "https://app.example.com/account",
    "lineNumber": 42,
    "columnNumber": 17
  }
}

Reports should be treated as signals rather than definitive proof of exploitation. A blocked inline script may be a false positive, a broken feature or an attack attempt. Conversely, a successful injection that executes within an already trusted nonce-bearing element may produce no CSP violation.

This is why CSP reporting works best when combined with application logs, dependency monitoring, route-level testing and user-agent information.

Practical checks for Mojarra applications

Teams using Mojarra should begin by confirming whether their deployments fall within the affected versions and whether URL-based client window mode is enabled.

The fixed versions are:

  • 4.0.29 for the 4.0 release branch
  • 4.1.20 for the 4.1 release branch
  • 5.0.0-M12 for the 5.0 milestone branch

A practical review should include:

  1. Identify all Mojarra versions in direct and transitive dependencies.
  2. Check whether the application uses:

    jakarta.faces.CLIENT_WINDOW_MODE=url
  3. Review whether CSP nonce support is enabled.
  4. Upgrade to Mojarra 4.0.29, 4.1.20 or 5.0.0-M12, depending on the deployed release branch.
  5. Inspect generated pages for request-derived values inside script blocks, event handlers and JavaScript string literals.
  6. Test values supplied through jfwid and jakarta.faces.ClientWindow using safe, non-destructive security test cases.
  7. Check that the same CSP is present on normal pages, redirects, error responses and authenticated routes.
  8. Review CSP reports for related blocked script and inline execution attempts.
  9. Verify that the deployment is not serving cached HTML with a stale nonce.
  10. Confirm that any intermediary proxy, cache or template layer does not alter the response after the nonce has been generated.

Upgrading is the primary remediation. If URL-based client window mode is not required, disabling it may reduce exposure while a patch is being prepared, but it should not replace the appropriate framework update.

How to test the trust boundary

A useful test is to ask a simple question:

Can any request-controlled value reach a script, style, URL or event-handler context that the application has marked as trusted?

The test should cover more than the main page. Review:

  • navigation components
  • buttons and links
  • redirect pages
  • validation messages
  • error handlers
  • partial page updates
  • server-side rendered fragments
  • HTML email previews
  • administrative interfaces
  • legacy pages that use different templates

Automated scanning can confirm whether the expected headers are present, but it cannot always determine whether a framework has inserted untrusted data into a trusted script element. Dynamic testing and source review are still needed.

Header monitoring remains valuable because it can detect drift. For example, an application may have a strong CSP on its main route but a weaker policy on an older administrative page. It may also send different policies through different load balancers or deployment environments.

A CSP dashboard can help correlate violations by route, directive, browser and deployment version. That makes it easier to distinguish a one-off browser extension report from a pattern associated with a particular release.

The broader lesson

CSP is a browser-enforced policy, but the server decides which content receives trust.

A nonce is therefore only as strong as the code that uses it. If a framework, template engine or application component places attacker-controlled data inside a nonce-bearing element, the browser has no reliable way to tell that the content was not intended by the server.

CVE-2026-120421 reinforces several practical principles:

  • use a fresh, unpredictable nonce for every dynamic response
  • never treat a nonce as a substitute for output encoding
  • encode data for its final context
  • keep trusted script blocks as small as possible
  • review framework-generated markup, not just application templates
  • use CSP reports to detect policy violations and configuration drift
  • combine CSP with Trusted Types, secure framework defaults and dependency patching
  • verify the actual response received by the browser

The goal is not to make CSP carry the entire burden of XSS prevention. The goal is to ensure that each layer has a clear responsibility.

CSP limits what the browser will execute. Safe rendering ensures that untrusted data does not become executable code in the first place. Together, they provide a much stronger boundary than either control can provide alone.