Repository navigation
fix(lockdown): #503 guard must not fire on locals shadowing a stdlib namespace name (#1701) - #1703
Merged
Conversation
…name (#1701) The #503 dynamic-stdlib-dispatch guard (`stdlib_namespace_receiver` in `lower/expr_member.rs`) matched any bare ident whose NAME equals a stdlib namespace (`path`, `fs`, …) as the namespace itself — without checking it wasn't a local variable / parameter shadowing that name. hono's trie-router has a `path` string parameter and does `path[0] === "/"`. The guard treated that local as the `node:path` namespace and refused the computed index as the `path[runtimeVar]()` obfuscation pattern, blocking the entire `hono` package from compiling (surfaced while verifying #1698 / unblocking the #1655 Hono `c.req.json()` path). Fix: a local binding that shadows a namespace name is the user's own variable, never the namespace (real namespaces are the global `process` or an import, which the alias / namespace-import branches resolve). Skip the direct name-match when `ctx.lookup_local(name).is_some()`. The refusal path for genuine namespace receivers is unchanged — verified a real `(fs as any)[k]()` is still refused, while a local `path[i]` now compiles. With this + #1698, a Hono `POST /api/echo` doing `await c.req.json()` compiles and runs by default (no `PERRY_ALLOW_DYNAMIC_STDLIB` bypass): status 200, body {"body":{"x":1}}. Test: test-files/test_issue_1701_local_shadows_stdlib_namespace.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #1701. The
#503dynamic-stdlib-dispatch guard refused any computed member access on a bare ident whose name equals a stdlib namespace (path,fs,crypto, …) — without checking it was actually the imported namespace rather than a local variable / parameter that happens to share the name.hono's trie-router has a
pathstring parameter and doespath[0] === "/". The guard treated that local as thenode:pathnamespace and refused the index as thepath[runtimeVar]()obfuscation pattern, blocking the entirehonopackage from compiling:(Surfaced while verifying #1698 / unblocking the #1655 Hono
c.req.json()path.)Fix
In
stdlib_namespace_receiver(crates/perry-hir/src/lower/expr_member.rs), skip the direct name-match when the ident is bound to a local (ctx.lookup_local(name).is_some()). A local that shadows a namespace name is the user's own variable, never the namespace — and a real stdlib namespace is the globalprocessor an import, both of which the alias / namespace-import branches resolve independently. So the refusal path for genuine namespace receivers is unchanged.Verification
(fs as any)[k]()is still refused with the security: refuse dynamic stdlib dispatch (obj[runtimeVar]()) #503 error.path[i]/fs[key]()/crypto[k]compiles and matchesnode --experimental-strip-types.POST /api/echodoingawait c.req.json()compiles and runs by default (noPERRY_ALLOW_DYNAMIC_STDLIBbypass) →status=200,body={"body":{"x":1}}.cargo fmt --all -- --checkclean;perry-hirunit tests pass.Test
test-files/test_issue_1701_local_shadows_stdlib_namespace.ts— locals named after stdlib namespaces (path/fs/crypto/os/url) with computed index + computed method call, all matching Node.Related: #1698 (Request body methods), #1655 (Hono tracker), #503 (the guard).