GeezerVison is showing github.com — id(web): detectLanguage returns Object.prototype members as languages — plain-object lookups on EXT_TO_LANG/FILENAME_TO_LANG trust arbitrary filenames ('notes.constructor' returns the Object constructor, '__proto__' returns a prototype object) · Issue #2787 · developing-today/code
id(web): detectLanguage returns Object.prototype members as languages — plain-object lookups on EXT_TO_LANG/FILENAME_TO_LANG trust arbitrary filenames ('notes.constructor' returns the Object constructor, '__proto__' returns a prototype object) #2787Labels app/idPackage/app: id (pkgs/ or apps/ in this repo)effort/xsTrivial: expected under 30 minutes of workkind/bugSomething isn't working (prefixed form of the classic bug label)priority/normalOrdinary priority (the default)source/creatorFiled by the new-issue-creator jobtask/small-fixQueue packet kind: bounded fix with reproduction and targeted tests DescriptionSummary
detectLanguage() in pkgs/id/web/src/highlight.ts does plain-object lookups on three unguarded maps with keys taken from an arbitrary, user-chosen filename, so a filename whose extension or stem is an all-lowercase Object.prototype member name returns a prototype member instead of undefined:
highlight.ts:149-151 — EXT_TO_LANG[ext], where ext is the lowercased extension of any document filename
highlight.ts:161-168 — FILENAME_TO_LANG[nameWithoutExt] and FILENAME_TO_LANG[basenameLower] with the lowercased stem / basename
Because the lookups are truthiness checks (if (ext && EXT_TO_LANG[ext]) return EXT_TO_LANG[ext];), inherited members count as hits. The declared return type is string | undefined, but at runtime the function returns a function or an object for these names.
Evidence (verified this run, real module)
Probe on the laptop (~/git/fleet/probe-2026-10-30-laneB-highlightproto/probe.ts, bun, importing the real highlight.ts from the laptop clone; file md5 a88efa332c0483144cb896388e248cc9 matches sandbox main at 24ddc153):
{"input":"notes.constructor","resultType":"function","result":"function Object() { [native code] }"}
{"input":"notes.__proto__","resultType":"object","result":"[object Object]"}
{"input":"constructor","resultType":"function","result":"function Object() { [native code] }"}
{"input":"__proto__","resultType":"object","result":"[object Object]"}
{"input":"notes.toString","resultType":"undefined"} // lowercasing breaks the camelCase key — only all-lowercase prototype names leak
{"input":"app.ts","resultType":"string","result":"typescript"} // control: correct
{"input":"Dockerfile","resultType":"string","result":"dockerfile"} // control: correct
{"input":"notes.unknownext","resultType":"undefined"} // control: correct
Neither map has an own constructor/__proto__ entry (Object.hasOwn(...) === false for both, verified in the same probe).
Why it matters
- The "language" for a file named e.g.
notes.constructor or data.__proto__ is a function/object, not a Shiki language id. It flows into createSyntaxHighlightPlugin as detectedLang and into the parser / languageExtractor (highlight.ts:325, 341, 379-386), where loadedLangs.has(lang), getLoadedLanguages().includes(lang) and the LANG_IMPORTS lookup all operate on a non-string: the file's code blocks silently never highlight, and any future consumer that treats the result as a string (concatenation, import() specifier, logging) gets function Object() { [native code] } / [object Object] instead of a language name.
- Same pattern in the same file:
ensureLanguage (highlight.ts:285) does LANG_IMPORTS[lang] where lang can be the authored code-block language attribute (markdown fence info string — arbitrary text). LANG_IMPORTS["constructor"] is the Object constructor (callable — it gets called as an import function) and LANG_IMPORTS["__proto__"] is a non-function object that then throws when called; both are only saved by the surrounding try/catch marking the language loaded.
- Filenames are user/document metadata in a peer-to-peer file-sharing app — they are exactly the kind of untrusted string these lookup tables must not trust. This is the same plain-object-prototype class the fleet has fixed in the aggregator / pm-dispatch lookups; the id web maps were missed.
Acceptance criteria
detectLanguage("notes.constructor"), detectLanguage("notes.__proto__"), detectLanguage("constructor") and detectLanguage("__proto__") all return undefined.
- All three lookup sites in
detectLanguage and the LANG_IMPORTS lookup in ensureLanguage only honour own properties of the maps (e.g. Object.hasOwn guard, Object.create(null) maps, or an equivalent own-key check) — a language attribute of constructor/__proto__ is treated as an unknown language, never called as an import function.
- Existing behaviour is unchanged for real extensions / special filenames (the current
highlight.test.ts suite passes, including the "every detected language has a grammar" guard from id(web): 13 detected languages can never highlight — detectLanguage returns them but LANG_IMPORTS has no grammar registered (bat, sass, zig, protobuf, .env, justfile, …) #749).
- New unit tests in
highlight.test.ts cover the prototype-name cases above for both the extension and the bare-filename paths.
Activityadded kind/bugSomething isn't working (prefixed form of the classic bug label) task/small-fixQueue packet kind: bounded fix with reproduction and targeted tests app/idPackage/app: id (pkgs/ or apps/ in this repo) effort/xsTrivial: expected under 30 minutes of work on Oct 30, 2026dezren39 commented on Oct 30, 2026 agent-note:v1
state: filed
Found via: filed this run by new-issue-creator-code-b (verified probe on laptop, real highlight.ts, md5-matched to main 24ddc15 — see issue body).
Plan: guarded self-solve per lifecycle protocol §4 — this is a trivial own-key guard on four lookup sites in one file with unit tests; creator-b will branch, fix, test on the laptop, and PR. No queue packet (self-solve path). dezren39 commented on Oct 30, 2026 agent-note:v1
state: self-solving
PR: #2788 (branch creator-b/2787-highlight-proto, commit 9ee4a5d) — Fixes marker in PR body. Verified on laptop worktree: probe post-fix all prototype names -> undefined, controls unchanged; vitest highlight 99/99; tsc clean. dezren39 commented on Oct 30, 2026 agent-note:v1
state: closed
Merged: PR #2788 (merge commit da42bfe) — verified on origin/main: Object.hasOwn guards at highlight.ts:151,162,166,286. Laptop verification: vitest highlight 99/99, tsc clean, post-fix probe all prototype names -> undefined. Closing as completed.
MetadataMetadataapp/idPackage/app: id (pkgs/ or apps/ in this repo)effort/xsTrivial: expected under 30 minutes of workkind/bugSomething isn't working (prefixed form of the classic bug label)priority/normalOrdinary priority (the default)source/creatorFiled by the new-issue-creator jobtask/small-fixQueue packet kind: bounded fix with reproduction and targeted tests DevelopmentNo branches or pull requestsIssue actions
|