feat(compiler): SYN015 — warn on localStorage/sessionStorage access that bypasses the storage capability model (?bs 0.7+) - #162
Open
marcelofarias wants to merge 19 commits into
Open
Conversation
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
localStorage.*orsessionStorage.*at?bs 0.7+reads {}/writes {}labels cover declared resource identifiers, not the Web Storage API globals. A fn that callslocalStorage.getItem(key)has an undeclared persistent state dependency — noreads {}declaration covers it, callers cannot see it, and it outlives the fn invocation (visible across unrelated calls and tabs on the same origin).Changes
packages/compiler/src/error-codes.tspackages/compiler/src/passes/syn-check.tscase "localStorage": case "sessionStorage":in dispatch loop — fires on any member access (.or?.), excludesobj.localStorage.*, bare references, and fn declarationspackages/compiler/tests/syn015-check.test.tspackages/compiler/tests/error-codes.test.tspackages/mcp/src/explanations.tspackages/mcp/tests/server.test.tsAGENTS.mdREADME.mdexplaintool code listTest plan
pnpm -r build && pnpm test— 1300 tests pass (46 test files)localStorage.getItem(key)localStorage.setItem(key, val)sessionStorage.getItem(key)sessionStorage.setItem(key, val)localStorage.removeItem(key)localStorage.clear()localStorage?.getItem(key)(optional chaining)localStorage.length(property access, not method call)?bs 0.7unsafe {}blocks orunsafe "reason" fnbodiesobj.localStorage.getItem(...)(member of a local)localStoragereference (no following.)fn localStorage(...)botscript declarations🤖 Generated with Claude Code