Skip to content

fix(@angular/build): assert that asset input paths are within workspace root#33222

Merged
alan-agius4 merged 1 commit into
angular:mainfrom
alan-agius4:asset-validation
May 21, 2026
Merged

fix(@angular/build): assert that asset input paths are within workspace root#33222
alan-agius4 merged 1 commit into
angular:mainfrom
alan-agius4:asset-validation

Conversation

@alan-agius4
Copy link
Copy Markdown
Collaborator

Ensure that asset patterns defined as objects with an 'input' property are validated to be within the workspace root.

  • In '@angular/build', introduce a shared 'isSubDirectory' utility and apply it to both 'normalizeAssetPatterns' and 'resolveAssets'.
  • In '@angular-devkit/build-angular', apply similar validation during 'normalizeAssetPatterns'.
  • Add integration tests to prevent regressions from absolute and relative path traversal attempts.

@alan-agius4 alan-agius4 requested review from clydin and dgp1130 May 20, 2026 09:25
@alan-agius4 alan-agius4 added the target: patch This PR is targeted for the next patch release label May 20, 2026
Copy link
Copy Markdown

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

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 introduces validation to ensure that asset input paths are located within the workspace root, adding a new isSubDirectory utility and corresponding checks across the application and browser builders. Feedback was provided regarding the path validation logic, specifically noting that the current use of startsWith('..') could lead to false positives for files or directories with names starting with double dots. It is recommended to refine these checks by accounting for path separators to ensure more robust path resolution.

Comment thread packages/angular/build/src/utils/path.ts Outdated
Comment thread packages/angular_devkit/build_angular/src/utils/normalize-asset-patterns.ts Outdated
@alan-agius4 alan-agius4 added the action: review The PR is still awaiting reviews from at least one requested reviewer label May 20, 2026
@alan-agius4 alan-agius4 force-pushed the asset-validation branch 6 times, most recently from 8430535 to db9ee2a Compare May 20, 2026 13:55
…ce root

Ensure that asset patterns defined as objects with an 'input' property are validated to be within the workspace root.

- In '@angular/build', introduce a shared 'isSubDirectory' utility and apply it to both 'normalizeAssetPatterns' and 'resolveAssets'.
- In '@angular-devkit/build-angular', apply similar validation during 'normalizeAssetPatterns'.
- Add and update integration and E2E tests to prevent regressions from absolute and relative path traversal attempts.
Comment on lines +47 to +50
const normalizedParent = normalize(parent);
const resolvedChild = resolve(parent, child);

return resolvedChild.startsWith(normalizedParent);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
const normalizedParent = normalize(parent);
const resolvedChild = resolve(parent, child);
return resolvedChild.startsWith(normalizedParent);
const resolvedParent = resolve(parent);
const resolvedChild = resolve(parent, child);
const relativePath = relative(resolvedParent, resolvedChild);
return !relativePath.startsWith('..') && !isAbsolute(relativePath);

Comment on lines +29 to +32
if (!isSubDirectory(root, entry.input)) {
throw new Error(`The ${entry.input} asset path must be within the workspace root.`);
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This should be moved so that it can be checked on a file-by-file basis in the loop below. A glob pattern can bypass this check.

@alan-agius4 alan-agius4 added action: merge The PR is ready for merge by the caretaker and removed action: review The PR is still awaiting reviews from at least one requested reviewer labels May 21, 2026
@alan-agius4 alan-agius4 removed the request for review from dgp1130 May 21, 2026 13:57
@alan-agius4 alan-agius4 merged commit 163a032 into angular:main May 21, 2026
35 checks passed
@alan-agius4 alan-agius4 deleted the asset-validation branch May 21, 2026 13:57
@alan-agius4
Copy link
Copy Markdown
Collaborator Author

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 target: patch This PR is targeted for the next patch release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants