Skip to content

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

Open
fowl2 wants to merge 3 commits into
angular:mainfrom
fowl2:test/csp-no-inline-content
Open

fowl2 wants to merge 3 commits 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: Related to angular/angular#70877 / angular/angular#70890

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).

Following the recent CSP guidance update for static hosting and CDN caching in angular/angular#70890 (requested in angular/angular#70877), this test helps ensure that guidance stays accurate over time by catching any future builder change that accidentally introduces inline scripts, inline styles, or inline event handlers into the generated HTML when those options are disabled.

Does this PR introduce a breaking change?

  • Yes
  • No

Other information

Replaces #34816 (closed before CLA signing completed; CLA is now signed).

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.

Loading
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.

1 participant