mirror of
https://github.com/morluto/rea.git
synced 2026-11-23 06:55:55 +00:00
fix(audit): preserve explicit source map schemes (#13345)
This commit is contained in:
1 parent
d35e142709
commit
d0929f9aa2
2 files changed
+49
-30
No files matched your search
@@ -4308,42 +4308,53 @@ describe("ReleaseExposureReader member identity", () => {
|
||||
expect(scanned.source_maps).toMatchObject({ embedded: 0, skipped: 1 });
|
||||
});
|
||||
|
||||
it.each([
|
||||
["app.js", "debug.json", { embedded: 1, skipped: 0 }],
|
||||
["z.js", "a.json", { embedded: 0, skipped: 1 }],
|
||||
])(
|
||||
"follows %s through a file: URL to the inventoried member %s",
|
||||
async (script, map, expected) => {
|
||||
it.for([
|
||||
["file URL", "app.js", "debug.json", true],
|
||||
["file URL", "z.js", "a.json", false],
|
||||
["Windows absolute path", "app.js", "debug.json", true],
|
||||
] as const)(
|
||||
"resolves a %s from %s to inventoried %s",
|
||||
async ([spelling, script, map, parsed], { skip }) => {
|
||||
const native = spelling === "Windows absolute path";
|
||||
if (native && process.platform !== "win32")
|
||||
skip("Windows path semantics");
|
||||
const root = await createTestTempDirectory("rea-release-file-url-map-");
|
||||
const url = pathToFileURL(join(root, map)).href;
|
||||
const target = join(root, map);
|
||||
const url = pathToFileURL(target);
|
||||
const reference = native ? url.pathname.slice(1) : url.href;
|
||||
await writeFile(
|
||||
join(root, script),
|
||||
`const value = 1;\n//# sourceMappingURL=${url}\n`,
|
||||
"//# sourceMappingURL=" + reference + "\n",
|
||||
);
|
||||
await writeFile(target, embeddedSourceMap());
|
||||
expect((await inspect(root)).source_maps).toMatchObject(
|
||||
parsed
|
||||
? { embedded: 1, embedded_paths: [target], skipped: 0 }
|
||||
: { embedded: 0, skipped: 1 },
|
||||
);
|
||||
await writeFile(join(root, map), embeddedSourceMap());
|
||||
const scanned = await inspect(root);
|
||||
expect(scanned.source_maps).toMatchObject(expected);
|
||||
},
|
||||
);
|
||||
|
||||
it.each(["debug.json", "debug.js.map"])(
|
||||
"counts a file: URL to %s outside the installation as skipped",
|
||||
async (map) => {
|
||||
const root = await createTestTempDirectory("rea-release-file-url-gone-");
|
||||
const outside = await createTestTempDirectory(
|
||||
"rea-release-file-url-out-",
|
||||
);
|
||||
const url = pathToFileURL(join(outside, map)).href;
|
||||
await writeFile(
|
||||
join(root, "app.js"),
|
||||
`const value = 1;\n//# sourceMappingURL=${url}\n`,
|
||||
);
|
||||
const scanned = await inspect(root);
|
||||
expect(scanned.source_maps).toMatchObject({ embedded: 0, skipped: 1 });
|
||||
},
|
||||
);
|
||||
it("keeps a shipped file: map outside the selected directory unexamined", async () => {
|
||||
const [root, outside] = await Promise.all([
|
||||
createTestTempDirectory("rea-release-file-url-gone-"),
|
||||
createTestTempDirectory("rea-release-file-url-out-"),
|
||||
]);
|
||||
const map = join(outside, "debug.js.map");
|
||||
await writeFile(map, embeddedSourceMap());
|
||||
await writeFile(
|
||||
join(root, "app.js"),
|
||||
"const value = 1;\n//# sourceMappingURL=" +
|
||||
pathToFileURL(map).href +
|
||||
"\n",
|
||||
);
|
||||
expect((await inspect(root)).source_maps).toMatchObject({
|
||||
embedded: 0,
|
||||
skipped: 1,
|
||||
});
|
||||
});
|
||||
|
||||
it("counts a malformed file: URL as skipped and ignores a remote map", async () => {
|
||||
it("skips a malformed file: URL and ignores scheme-qualified remote maps", async () => {
|
||||
const root = await createTestTempDirectory("rea-release-file-url-bad-");
|
||||
await writeFile(
|
||||
join(root, "bad.js"),
|
||||
@@ -4353,6 +4364,12 @@ describe("ReleaseExposureReader member identity", () => {
|
||||
join(root, "remote.js"),
|
||||
"const value = 2;\n//# sourceMappingURL=https://example.com/debug.json\n",
|
||||
);
|
||||
await writeFile(
|
||||
join(root, "short.js"),
|
||||
"//# sourceMappingURL=x:decoy.data\n",
|
||||
);
|
||||
if (process.platform !== "win32")
|
||||
await writeFile(join(root, "x:decoy.data"), embeddedSourceMap());
|
||||
const scanned = await inspect(root);
|
||||
expect(scanned.source_maps).toMatchObject({ embedded: 0, skipped: 1 });
|
||||
});
|
||||
|
||||
@@ -121,6 +121,7 @@ import {
|
||||
} from "../filesystem/RegularFile.js";
|
||||
import { sourceMapJsonText } from "../domain/sourceMapEnvelope.js";
|
||||
import {
|
||||
hasScheme,
|
||||
htmlUrlText,
|
||||
stripQueryAndFragment,
|
||||
} from "../domain/artifactPathSyntax.js";
|
||||
@@ -2217,7 +2218,8 @@ const examineInlineMaps = (
|
||||
* examined as ordinary text was not assessed as a map, so coverage is unknown.
|
||||
* A `file:` URL names one absolute location rather than a path beside the
|
||||
* script, so even a `.map` target stays unassessed until that location is
|
||||
* reached. Any other scheme is remote.
|
||||
* reached. Other schemes name external references. A native absolute path
|
||||
* may contain a Windows drive colon.
|
||||
*/
|
||||
const noteLocalMapReference = (
|
||||
state: ScanState,
|
||||
@@ -2238,7 +2240,7 @@ const noteLocalMapReference = (
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (/^[a-z][a-z0-9+.-]+:/iu.test(url)) return;
|
||||
if (!isAbsolute(path) && hasScheme(url)) return;
|
||||
if (path.length === 0) return;
|
||||
let decoded: string;
|
||||
try {
|
||||
|
||||
Reference in new issue
Block a user