Skip to content

fix(@angular/build): use isSubDirectory in normalizeAssetPatterns and ignore nested .gitkeep - #34420

Merged
alan-agius4 merged 5 commits into
angular:mainfrom
alan-agius4:fix/asset-utils-prefix-and-gitkeep
Oct 20, 2026
Merged

alan-agius4 merged 5 commits into
angular:mainfrom
alan-agius4:fix/asset-utils-prefix-and-gitkeep

Conversation

@alan-agius4

Copy link
Copy Markdown
Collaborator

Summary

  • Replace .startsWith(...) checks in normalizeAssetPatterns with isSubDirectory(...) to prevent sibling directory prefix collisions (e.g. src-assets when sourceRoot is src).
  • Change '.gitkeep' to '**/.gitkeep' in DEFAULT_ASSET_IGNORE (resolve-assets.ts) so .gitkeep files in nested subdirectories are also ignored.
  • Validate in resolveAssets that resolved destination paths do not escape the output root via .. (e.g. when glob contains ..).

… ignore nested .gitkeep

- Replace `.startsWith(...)` prefix checks in `normalizeAssetPatterns` with `isSubDirectory(...)` so sibling directories sharing a prefix with `sourceRoot`, `projectRoot`, or `workspaceRoot` (such as `src-assets` when `sourceRoot` is `src`) are resolved against the proper parent directory instead of producing a `..` output path error.
- Update `DEFAULT_ASSET_IGNORE` in `resolve-assets.ts` from `'.gitkeep'` to `'**/.gitkeep'` so nested `.gitkeep` files are also ignored, matching `'**/.DS_Store'` and `'**/Thumbs.db'`.
- Validate that resolved asset `destination` paths in `resolveAssets` do not escape the output root via `..`.
@alan-agius4
alan-agius4 requested a review from clydin October 20, 2026 09:37
@alan-agius4 alan-agius4 added action: review The PR is still awaiting reviews from at least one requested reviewer target: minor This PR is targeted for the next minor release labels Oct 20, 2026
@alan-agius4
alan-agius4 marked this pull request as ready for review October 20, 2026 09:37

@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 enhances asset path normalization and resolution by utilizing isSubDirectory checks and introducing a resolveDestination helper to prevent assets from escaping the output directory. It also updates the default asset ignore patterns to ignore .gitkeep files globally and adds comprehensive unit tests. Feedback was provided regarding a potential path traversal vulnerability on Windows if the destination path becomes absolute, suggesting an additional check for absolute paths to prevent escaping the output directory.

Comment thread packages/angular/build/src/utils/resolve-assets.ts Outdated
@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 Oct 20, 2026
@alan-agius4
alan-agius4 merged commit 58c30c0 into angular:main Oct 20, 2026
40 checks passed
@alan-agius4
alan-agius4 deleted the fix/asset-utils-prefix-and-gitkeep branch October 20, 2026 15:50
@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: minor This PR is targeted for the next minor release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants