fix(permissions-policy): recognize any non-wildcard directive value as restrictive#76
Open
dmchaledev wants to merge 1 commit into
Open
fix(permissions-policy): recognize any non-wildcard directive value as restrictive#76dmchaledev wants to merge 1 commit into
dmchaledev wants to merge 1 commit into
Conversation
…s restrictive
The previous check used literal `.includes("camera=()")`, which only matched
the deny-all form and incorrectly flagged valid restrictive policies like
`camera=(self)` or `camera=(https://trusted.example.com)` as warnings (score 5
instead of 10). The new `isPermissionsPolicyFeatureRestricted` helper parses
the directive properly: any `feature=(...)` value passes; only the bare `*`
wildcard (allow-all) does not.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011rKFKyLpkTsT5DeJi8yw8U
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.
Bug
checkPermissionsPolicyused literal string matching to detect whether a feature was restricted:This only matched the deny-all form
=(). Any other valid restrictive value —camera=(self),camera=(https://trusted.example.com)— caused a false-positive warning and dropped the score from 10 to 5, with the misleading message "Permissions-Policy does not restrict at least camera, microphone, and geolocation" even though the policy does restrict all three.Real-world policies commonly use
=(self)to allow camera/microphone on the same origin while blocking third-party iframes. These were incorrectly penalised.Fix
Added
isPermissionsPolicyFeatureRestricted(policy, feature)which parses the directive properly:feature=()→ restricted (deny all)feature=(self)→ restricted (allow same-origin)feature=(https://example.com)→ restricted (specific allowlist)feature=*→ not restricted (wildcard, allow all origins)The helper also guards against partial suffix matches (e.g.
notcamera=()should not satisfy thecameracheck).Tests
Four new test cases added to
analyzer.test.ts:camera=(self), microphone=(self), geolocation=()camera=(https://example.com), microphone=(), geolocation=()camera=*, microphone=(), geolocation=()notcamera=(), microphone=(), geolocation=()All 89 tests pass.
🤖 Generated with Claude Code
https://claude.ai/code/session_011rKFKyLpkTsT5DeJi8yw8U
Generated by Claude Code