enhance(#3624): local/no-exact-case-env-access — ratchet ADR-1703 onto production env reads (epic #3411 Phase 4) (#3976)
* enhance(#3624): local/no-exact-case-env-access — ratchet ADR-1703 onto production env reads (epic #3411 Phase 4) Extends ADR-1703's portability rule catalog with a second production-runtime rule: it flags an exact-case read of a Windows case-varying environment variable (PATH, PATHEXT, ComSpec, USERPROFILE, TEMP, TMP, APPDATA) off any receiver that is not process.env itself, matched via an env-shaped-receiver check to avoid colliding with ordinary `.path`-named properties elsewhere in the tree. Exports the seam's private `_envGet` as `envGet` so the rule's remediation message names a real helper, and fixes the one pre-existing violation the tightened rule found (`src/runtime-hooks-surface.cts`'s `env.APPDATA` read). Closes #3624 * fix(#3624): extractStaticName recognizes non-computed Literal destructuring keys; add missing accessor-call test case Review findings from the code-review + isolated-adversarial passes: - extractStaticName only matched non-computed Identifier keys, so a destructuring like `const { 'PATH': v } = opts.env;` (the issue's own I8 acceptance case) silently evaded the rule. Widened to accept a Literal key regardless of computed, which is safe for MemberExpression too (its non-computed property is always an Identifier by grammar). - Added the missing RuleTester valid case for "a case-insensitive accessor call" (envGet(env, 'PATH')) from the issue's Done-when checklist. * docs: backfill changeset PR number for #3624 (PR #3976) --------- Co-authored-by: sim <sim@local>
This commit is contained in:
@@ -100,6 +100,32 @@ const WINDOWS_EXECUTABLE_EXTENSIONS = ['.exe', '.cmd', '.bat', '.com'];
|
||||
*/
|
||||
const PATHEXT_VAR_NAME = 'PATHEXT';
|
||||
|
||||
/**
|
||||
* Windows environment variable names whose CONVENTIONAL casing varies from the
|
||||
* all-uppercase POSIX convention (`Path` not `PATH`, `ComSpec` not `COMSPEC`,
|
||||
* `TEMP`/`TMP`/`APPDATA`/`USERPROFILE` as shipped by Windows). `process.env` is
|
||||
* a case-insensitive Proxy that hides this on every platform, so
|
||||
* `process.env.PATH` is always safe — but a plain object (a spread of
|
||||
* `process.env`, a function parameter, any object that is not literally
|
||||
* `process.env` at the access site) keeps the OS's actual casing and an
|
||||
* exact-case lookup against it silently returns `undefined` on Windows.
|
||||
* local/no-exact-case-env-access matches a read of ANY casing of ANY of these
|
||||
* names off ANY receiver that is not `process.env` itself (#3624, epic #3411
|
||||
* Phase 4).
|
||||
*/
|
||||
const WINDOWS_CASE_VARYING_ENV_VARS = ['PATH', 'PATHEXT', 'ComSpec', 'USERPROFILE', 'TEMP', 'TMP', 'APPDATA'];
|
||||
|
||||
const WINDOWS_CASE_VARYING_ENV_VARS_LOWER = new Set(WINDOWS_CASE_VARYING_ENV_VARS.map((v) => v.toLowerCase()));
|
||||
|
||||
/**
|
||||
* True when `name` case-insensitively matches one of WINDOWS_CASE_VARYING_ENV_VARS.
|
||||
* @param {string} name
|
||||
* @returns {boolean}
|
||||
*/
|
||||
function isCaseVaryingEnvVarName(name) {
|
||||
return typeof name === 'string' && WINDOWS_CASE_VARYING_ENV_VARS_LOWER.has(name.toLowerCase());
|
||||
}
|
||||
|
||||
/**
|
||||
* Boundary-aware match for each WINDOWS_EXECUTABLE_EXTENSIONS entry, in the
|
||||
* same order. A plain substring test misfires on ordinary prose/event-name
|
||||
@@ -403,6 +429,8 @@ module.exports = {
|
||||
PATH_RETURNING_FNS,
|
||||
WINDOWS_EXECUTABLE_EXTENSIONS,
|
||||
PATHEXT_VAR_NAME,
|
||||
WINDOWS_CASE_VARYING_ENV_VARS,
|
||||
isCaseVaryingEnvVarName,
|
||||
countWindowsExecutableExtensions,
|
||||
isPathReturningCall,
|
||||
isPosixSlashStringLiteral,
|
||||
|
||||
Reference in New Issue
Block a user