Repository navigation
fix(@angular/build): escape providersFile specifier in generated Vitest test setup - #33899
herdiyana256 wants to merge 1 commit into
Conversation
…st test setup The Vitest unit-test runner builds the TestBed initialization virtual file by interpolating the `providersFile` path from the project configuration directly into an import statement. A value containing a quote or newline terminated the import specifier early, so the trailing text was emitted as executable code in the generated file and ran when the tests were executed. The specifier is now constructed with `JSON.stringify`, so any quotes, backslashes, or newlines in the path are escaped and the value can only ever be a single string literal.
There was a problem hiding this comment.
Code Review
This pull request exports the createTestBedInitVirtualFile function and updates it to use JSON.stringify when generating the import path for providersImport. This change prevents potential code injection vulnerabilities by escaping quotes, backslashes, and newlines in the providersFile path. Additionally, a new test suite build-options_spec.ts has been added to verify correct behavior and ensure malicious paths are properly escaped. I have no feedback to provide.
|
Thanks for this, but closing with the same rational of #33722 |
|
This pull request has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
The Vitest unit-test runner builds the TestBed initialization virtual file by interpolating the
providersFilepath into an import statement.importPathcomes from theprovidersFilebuilder option viapath.relative/path.parse/path.join, none of which strips quotes or newlines, and the option has no schema pattern:A value containing a single quote closes the specifier early, so the trailing characters are emitted as top-level code in the generated file and run when the tests execute. For example,
providersFile: "src/x';someCode();'"with a regularsrc/x.tspresent generates:and
someCode()runs duringng test.This builds the specifier with
JSON.stringifyso any quotes, backslashes, or newlines are escaped and the value can only ever be a single string literal, matching the escaping already used for generated imports elsewhere:Adds a unit test covering the quote and newline cases.