fix: preserve model state, isolate commands and harden local HTTP in 1.12.1
This commit is contained in:
@@ -0,0 +1,11 @@
|
||||
import path from 'node:path';
|
||||
|
||||
// Project commands receive system/runtime paths, never arbitrary host settings
|
||||
// or provider credentials. Additional fields are explicit internal policy.
|
||||
export function projectEnvironment(extra = {}) {
|
||||
const allowed = /^(path|pathext|systemroot|systemdrive|windir|comspec|temp|tmp|userprofile|homedrive|homepath|home|appdata|localappdata|programfiles(?:\(x86\))?|commonprogramfiles(?:\(x86\))?|lang|lc_all)$/i;
|
||||
const environment = Object.fromEntries(Object.entries(process.env).filter(([name]) => allowed.test(name)));
|
||||
const inheritedPath = Object.entries(environment).find(([name]) => name.toLowerCase() === 'path')?.[1] || '';
|
||||
for (const name of Object.keys(environment)) if (name.toLowerCase() === 'path') delete environment[name];
|
||||
return { ...environment, PATH: [path.dirname(process.execPath), inheritedPath].filter(Boolean).join(path.delimiter), ...extra };
|
||||
}
|
||||
Reference in New Issue
Block a user