Skip to content

test(@angular/build): verify no inline scripts or styles in CSR index.html - #34816

Closed
fowl2 wants to merge 1 commit into
angular:mainfrom
fowl2:test/csp-no-inline-content
Closed

fowl2 wants to merge 1 commit into
angular:mainfrom
fowl2:test/csp-no-inline-content

Conversation

@fowl2

@fowl2 fowl2 commented Dec 2, 2026 •

Copy link
Copy Markdown

PR Checklist

Please check if your PR fulfills the following requirements:

PR Type

What kind of change does this PR introduce?

  • Bugfix
  • Feature
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • CI related changes
  • Documentation content changes
  • Other... Please describe: Regression test coverage for strict-CSP static index.html output

What is the current behavior?

Individual index-HTML transformations (inlineCritical, subresourceIntegrity, autoCsp, fonts, csp-nonce) are each tested separately, but there is no builder-level regression test verifying that @angular/build:application emits zero inline scripts, inline styles, inline event handlers, or CSP <meta> tags in the final generated HTML when all inline-emitting options are disabled.

Issue Number: N/A

What is the new behavior?

Adds packages/angular/build/src/builders/application/tests/behavior/csp-inline-content_spec.ts using the existing htmlRewritingStream parser (parse5-html-rewriting-stream) and isJavascriptMimeType helper to assert that:

  1. Optimized CSR build (with lazy route, polyfills: ['zone.js'], global scripts, global styles, baseHref + index.preloadInitial: true, sourceMap: { scripts: true }, outputHashing: All, optimization.styles.inlineCritical: false, optimization.fonts: false, subresourceIntegrity: false, and security.autoCsp unset) emits external scripts and stylesheets and zero:
    • inline <script> tags (any <script> without src)
    • inline <style> tags
    • inline style="..." attributes
    • inline on* event handler attributes
    • CSP <meta http-equiv="Content-Security-Policy*"> tags
  2. Unoptimized CSR build (optimization: false, subresourceIntegrity: false) maintains the same guarantee.
  3. Static prerendered build (outputMode: OutputMode.Static, without withEventReplay(), with inlineCritical: false, fonts: false, subresourceIntegrity: false) emits external scripts and stylesheets and zero executable inline <script> tags, inline on* event handler attributes, or CSP <meta> tags in both dist/browser/index.csr.html and the prerendered dist/browser/lazy/index.html (allowing non-executable data blocks such as type="application/json" and serialized component <style> tags).

This guards statically hosted apps that enforce a strict response-header CSP (e.g. script-src 'self') against new builder features accidentally introducing inline scripts or event handlers into the generated HTML.

Does this PR introduce a breaking change?

  • Yes
  • No

Other information

Verified locally with Bazel:

  • pnpm bazel test //packages/angular/build:application_integration_test_lib_strict_deps_test (PASSED)
  • pnpm bazel test //packages/angular/build:application_integration_tests --test_arg=--filter="CSP without inline scripts or styles" (3 specs, 0 failures)
  • pnpm exec prettier --check packages/angular/build/src/builders/application/tests/behavior/csp-inline-content_spec.ts (passed)
  • pnpm ts-circular-deps check (0 cycles)

Disclosure: AI coding assistance (GitHub Copilot) was used to help draft and verify this test.

….html

Add an application builder behavior test asserting that dist/browser/index.html
contains no inline <script> tags, inline <style> tags, inline style attributes,
inline event handler attributes, or CSP <meta> tags when inlineCritical, fonts,
subresourceIntegrity, and autoCsp are disabled (both optimized and unoptimized
CSR builds with lazy chunks and stylesheets).

Static-hosted applications using a strict response-header CSP (such as
script-src 'self') rely on the builder not introducing inline markup in
index.html under this configuration.
@google-cla

google-cla Bot commented Dec 2, 2026

Copy link
Copy Markdown

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@alan-agius4

Copy link
Copy Markdown
Collaborator

Closing as CLA has not been signed.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants