Skip to content
Source
Sign inSign up
pingdotgg/t3code

fix(server): unset the allow-scripts policy npx exports before installing the pinned runtime #9403

Closedylcn91(GitHub profile, opens in a new tab)wants to merge 1 commit intomain fromrefs/pull/9403/headopened View on GitHub

Showing 2 changed files with 75 additions and 0 deletions.

x
0 of 2 viewed, 2 left
61 additions and 0 deletionsapps/server/src/cloud/pinnedRuntime.test.tsModified
View file
@@ -228,6 +228,67 @@
}),
​
+ it.effect("drops every spelling of the inherited allow-scripts policy from the installer", () =>
+ Effect.gen(function* () {
+ const fs = yield* FileSystem.FileSystem;
+ const path = yield* Path.Path;
+ const baseDir = yield* fs.makeTempDirectoryScoped({ prefix: "t3-pinned-runtime-env-" });
+ // npx exports the lowercase name and npm reads the uppercase one just the
+ // same. Unrelated npm configuration must still reach the child.
+ const stubbed = {
+ npm_config_allow_scripts: "true",
+ NPM_CONFIG_ALLOW_SCRIPTS: "true",
+ npm_config_registry: "https://registry.example.test/",
+ };
+ const previous = Object.fromEntries(
+ Object.keys(stubbed).map((key) => [key, process.env[key]]),
+ );
+ Object.assign(process.env, stubbed);
+ yield* Effect.addFinalizer(() =>
+ Effect.sync(() => {
+ for (const [key, value] of Object.entries(previous)) {
+ if (value === undefined) delete process.env[key];
+ else process.env[key] = value;
+ }
+ }),
+ );
+​
+ // Spawn a real child with exactly what the installer hands npm, so the