Skip to content

feat(@angular/build): emit debug ids for stable subresource integrity hashes#33110

Merged
dgp1130 merged 1 commit into
angular:mainfrom
simpleclub-extended:feat/sub-resource-integrity-with-debug-id
Jul 15, 2026
Merged

feat(@angular/build): emit debug ids for stable subresource integrity hashes#33110
dgp1130 merged 1 commit into
angular:mainfrom
simpleclub-extended:feat/sub-resource-integrity-with-debug-id

Conversation

@IchordeDionysos

@IchordeDionysos IchordeDionysos commented Apr 30, 2026

Copy link
Copy Markdown
Contributor

Enable generating sub-resource integrity hashes when using error tracking tools relying on Debug IDs linking generated code files with source maps.

Closes #33108

PR Checklist

Please check to confirm 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:

What is the current behavior?

When Angular generates source maps, they only include a link to the source map URL and no Debug ID:

console.log(1);
//# sourceMappingURL=foo.js.map

The source map file also does not contain a debug ID:

{ "version": 3, "debugId": "old", "mappings": "" }

Issue Number: #33108

What is the new behavior?

When Angular generates source maps, in addition to the source map URL, generated files will also include a Debug ID above the sourceMappingURL:

console.log(1);
//# debugId=11111111-2222-5333-9444-555555555555
//# sourceMappingURL=foo.js.map

In addition the source map file will include the matching Debug ID:

{ "version": 3, "debugId": "old", "mappings": "", "debugId": "11111111-2222-5333-9444-555555555555" }

Does this PR introduce a breaking change?

  • Yes
  • No

Other information

I'm happy to hear if there are concerns with this particular approach and which alternative solutions might be a better solution.

This allows error tracking to more reliably map generated code files to their corresponding stack traces.
Error tracking tools have historically solved this by running post-processing scripts that generate and inject Debug IDs after the framework build script and before deployment.

However, this approach will break any integrity hash that Angular generated for SRI as the file content will have changed.

--

This PR is part of a two fold effort to enable SRI for our specific integration of Angular.

The first PR, implementing support for dynamically loaded files can be found here, and should be merged first: #33109

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request implements ECMA-426 Debug ID injection into JavaScript files and source maps using a new deterministic UUIDv5 utility. The injection is integrated into the post-bundle build process and includes validation tests. Review feedback suggests hardening the regex for comment detection to prevent false positives and optimizing the source map JSON update to maintain formatting and performance.

Comment thread packages/angular/build/src/utils/debug-id.ts Outdated
Comment thread packages/angular/build/src/utils/debug-id.ts Outdated
Comment on lines +30 to +41
export function generateDebugId(name: string | Uint8Array): string {
const sha = createHash('sha1').update(ANGULAR_BUILD_NAMESPACE).update(name).digest();

// Set version (5) in the high nibble of byte 6.
sha[6] = (sha[6] & 0x0f) | 0x50;
// Set RFC 4122 variant bits (10xx) in byte 8.
sha[8] = (sha[8] & 0x3f) | 0x80;

const h = sha.toString('hex');

return `${h.slice(0, 8)}-${h.slice(8, 12)}-${h.slice(12, 16)}-${h.slice(16, 20)}-${h.slice(20, 32)}`;
}

@IchordeDionysos IchordeDionysos Apr 30, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There would also be the possibility of using an existing implementation, e.g. of uuid.

Happy to make this change.

@clydin

clydin commented Jun 3, 2026

Copy link
Copy Markdown
Member

Sorry for the delay. Just the comment about the regular expressions and this should be good to merge.
We may need to look at performance aspects in the prereleases for 22.1 but that can happen after this lands.

Also please squash the commits.

Comment thread packages/angular/build/src/utils/debug-id.ts
@IchordeDionysos IchordeDionysos force-pushed the feat/sub-resource-integrity-with-debug-id branch from 29e12e5 to 11b40dc Compare June 13, 2026 15:06
@IchordeDionysos

Copy link
Copy Markdown
Contributor Author

@clydin no worries you were probably more focused on the 22 release with it's amazing features 😍
Sorry it took a bit longer, was a bit out of the topic due to it being a while ago.

Adjusted the Regex and did one minor incorrect test assumption.

@clydin clydin added the target: minor This PR is targeted for the next minor release label Jun 24, 2026
@clydin

clydin commented Jul 13, 2026

Copy link
Copy Markdown
Member

@IchordeDionysos While reviewing open PRs, we noticed this has some build failures. If you could address those, we should be able to get this merged.

@IchordeDionysos IchordeDionysos force-pushed the feat/sub-resource-integrity-with-debug-id branch from 557bb06 to db6397d Compare July 14, 2026 17:19
@IchordeDionysos

IchordeDionysos commented Jul 14, 2026

Copy link
Copy Markdown
Contributor Author

@clydin ahh damn must've been due to the refactor of files between the time I opened the PR and now...

Fixed now the affected commands that failed in CI. They are now passing on my MacBook (I hope the same is true on the Windows machines 👀).

… hashes

Enable generating sub-resource integrity hashes when using error tracking tools relying on Debug IDs linking generated code files with source maps.

Closes angular#33108
fix: persist formatting of source map JSON

fix: improve source map comment detection and test fix

format

fix import error

fix imports
@IchordeDionysos IchordeDionysos force-pushed the feat/sub-resource-integrity-with-debug-id branch from db6397d to d7752aa Compare July 14, 2026 17:50
@IchordeDionysos

IchordeDionysos commented Jul 14, 2026

Copy link
Copy Markdown
Contributor Author

Yes all checks passed 😍 🙌🏽

@clydin clydin added the action: merge The PR is ready for merge by the caretaker label Jul 14, 2026
@dgp1130 dgp1130 merged commit 0c18dc0 into angular:main Jul 15, 2026
40 checks passed
@dgp1130

dgp1130 commented Jul 15, 2026

Copy link
Copy Markdown
Collaborator

This PR was merged into the repository. The changes were merged into the following branches:

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

Labels

action: merge The PR is ready for merge by the caretaker area: @angular/build detected: feature PR contains a feature commit target: minor This PR is targeted for the next minor release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Emit ECMA-426 source map debug IDs for stable subresource integrity

3 participants