Skip to content

feat: $sce Strict Contextual Escaping (spec 012)#28

Merged
Mgrdich merged 6 commits intomasterfrom
sce-security
Apr 27, 2026
Merged

feat: $sce Strict Contextual Escaping (spec 012)#28
Mgrdich merged 6 commits intomasterfrom
sce-security

Conversation

@Mgrdich
Copy link
Copy Markdown
Owner

@Mgrdich Mgrdich commented Apr 24, 2026

Summary

Ships spec 012 — Strict Contextual Escaping ($sce). Removes the TODO(spec-$sce) marker left by spec 011 and delivers the full AngularJS 1.x-parity security surface in two layered forms (ESM-first primary + DI thin shims), matching architecture.md §1.

  • ESM primary: createSce / sce, createSceDelegate / sceDelegate, full trustAs* / getTrusted* / parseAs* shortcuts across the 5 public contexts (html, url, resourceUrl, js, css), SCE_CONTEXTS, and the TrustedValue class hierarchy (TrustedResourceUrl extends TrustedUrl for AngularJS subtype parity).
  • DI thin shims: $SceProvider / $SceDelegateProvider registered on ngModule. $sceProvider.enabled(value?) toggles strict mode at config time (default ON). $sceDelegateProvider.trustedResourceUrlList / .bannedResourceUrlList configure the resource-URL matcher with 'self', string wildcards (** / * with AngularJS [^:/?#]* parity), and RegExp entries. Block-list wins over allow-list.
  • $interpolate integration: trustedContext narrowed from stringSceContext; compile-time single-binding enforcement when strict mode is active; render-time trust unwrapping via $sce.getTrusted.
  • Public surface: ./sce subpath added to package.json exports and rollup.config.mjs; @sce/* path alias added to tsconfig.json, vitest.config.ts, rollup.config.mjs.

Test plan

  • pnpm lint — clean
  • pnpm format:check — clean
  • pnpm typecheck — clean (tsc --noEmit)
  • pnpm test — 1294/1294 green across 31 files (+221 tests vs. baseline 1073; 8 new test files cover ESM factory, delegate, provider, DI integration, interpolate-sce integration, resource-URL matcher; 11 tests ported from upstream sceSpecs.js)
  • pnpm build — dual ESM + CJS + .d.ts generated for every subpath including new ./sce
  • Regression: all prior specs (003, 007, 008, 009, 010, 011) pass unchanged
  • AWOS verification: every acceptance criterion in functional-spec.md marked [x]; spec + tech-considerations Status set to Completed; roadmap Security ($sce) item ticked

Docs

  • CLAUDE.md gains ./interpolate + ./sce Modules rows, two non-obvious invariants (frozen strict mode; TrustedResourceUrl subtype rule), and two "where to look" entries.
  • context/product/product-definition.md § 2.1 Core Features lists Security ($sce) with both surfaces named.
  • TSDoc @example blocks show the typical allow-list config and the $sce.trustAsHtml + $interpolate pairing.

🤖 Generated with Claude Code

Mgrdich and others added 6 commits April 23, 2026 15:22
Co-Authored-By: Claude <noreply@anthropic.com>
Ships the full $sce surface in two layered forms, matching the ESM-first
architecture convention (architecture.md §1) and the spec-011 precedent:

- ESM primary: createSce / sce, createSceDelegate / sceDelegate, with
  trustAs* / getTrusted* / parseAs* shortcuts across the five public
  contexts (html, url, resourceUrl, js, css) plus SCE_CONTEXTS and the
  TrustedValue class hierarchy (TrustedResourceUrl extends TrustedUrl for
  AngularJS subtype parity).
- DI thin shims: $SceProvider and $SceDelegateProvider registered on the
  ng module. $sceProvider.enabled(value?) toggles strict mode at config
  time (default ON); $sceDelegateProvider.trustedResourceUrlList and
  .bannedResourceUrlList configure the resource-URL matcher with 'self',
  string wildcards (** / *), and RegExp entries. Block-list wins over
  allow-list.
- $interpolate integration: trustedContext narrowed from string to
  SceContext, single-binding rule enforced at compile time when strict
  mode is active, and render-time trust unwrapping via $sce.getTrusted.
  Removes the TODO(spec-\$sce) marker left by spec 011.
- Public surface: ./sce subpath added to package.json exports and
  rollup.config.mjs; @sce/* path alias added to tsconfig, vitest,
  rollup. Root src/index.ts re-exports the ESM surface.
- Tests: +221 tests (1073 → 1294) across 8 new test files covering
  ESM path, delegate path, provider path, DI integration, interpolate
  integration, resource-URL matcher, and 11 ported AngularJS parity
  tests from upstream sceSpecs.js.
- Docs: CLAUDE.md gains ./interpolate and ./sce module rows, two
  non-obvious invariants (frozen strict mode, TrustedResourceUrl
  subtype rule), and new "where to look" entries.

All acceptance criteria in functional-spec.md verified. Final gate:
pnpm lint / format:check / typecheck / test / build all green.

Co-Authored-By: Claude <noreply@anthropic.com>
…ate tests

Co-Authored-By: Claude <noreply@anthropic.com>
Co-Authored-By: Claude <noreply@anthropic.com>
Co-Authored-By: Claude <noreply@anthropic.com>
@Mgrdich Mgrdich merged commit 0b926c8 into master Apr 27, 2026
2 checks passed
@Mgrdich Mgrdich deleted the sce-security branch April 27, 2026 18:46
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