fix(@angular/build): assert that asset input paths are within workspace root#33222
Conversation
There was a problem hiding this comment.
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.
8430535 to
db9ee2a
Compare
…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.
db9ee2a to
439f92c
Compare
| const normalizedParent = normalize(parent); | ||
| const resolvedChild = resolve(parent, child); | ||
|
|
||
| return resolvedChild.startsWith(normalizedParent); |
There was a problem hiding this comment.
| 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); |
| if (!isSubDirectory(root, entry.input)) { | ||
| throw new Error(`The ${entry.input} asset path must be within the workspace root.`); | ||
| } | ||
|
|
There was a problem hiding this comment.
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.
Ensure that asset patterns defined as objects with an 'input' property are validated to be within the workspace root.