feat: Manage allowlists from the rules-picker UI - #46
Merged
Conversation
Closes #42. The local web UI only exposed per-rule enable/disable checkboxes, so the three allowlist knobs (allowedDomains, allowedValues, allowedPatterns) could only be set by hand-editing .privacy-guard.json. - Add src/cli/validate.ts: validateAllowedPattern mirrors ScannerEngine.compileAllowedPatterns (parseable regex + safe-regex2 ReDoS check) so the UI accepts exactly the patterns the scanner would actually compile, instead of letting them be silently dropped at load time. parseAllowlists normalizes (domains trimmed/lowercased), drops empties, dedupes, and throws on any unusable entry so a failed save leaves the config untouched. - config-writer: generalize to a writeConfigKeys merge and add writeAllowlists. Allowlists keep the order the user added them (the list is hand-curated and order carries intent) while disabledRules stays sorted for stable diffs; every other key in the file is preserved. - server: add POST /save-allowlists and POST /validate-pattern, both token-checked like /save, and extract a shared readJsonBody helper (body cap, content-type check, 400 on thrown validation errors) now that three routes need it. Startup output reports allowlist counts. - page: split the UI into Rules and Allowlists tabs (proper tablist/tabpanel roles), with add/remove rows per list, autosave, and live regex feedback while typing in the pattern field. - tests/allowlist-config-ui.test.ts: 17 tests covering pattern validation against the scanner, payload normalization/rejection, and the config writer preserving unrelated keys across rule and allowlist saves. - README: document the two tabs, the regex validation, and that only the keys shown in the UI are rewritten. - Rebuild dist.
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.
Closes #42.
The local web UI (
npx claude-code-privacy-guard rules) only exposed per-rule enable/disable checkboxes, so the three allowlist knobs added in #41 could only be set by hand-editing.privacy-guard.json. This adds an Allowlists tab alongside Rules.What's in it
src/cli/validate.ts(new) βvalidateAllowedPatternmirrorsScannerEngine.compileAllowedPatterns(parseable regex +safe-regex2ReDoS check), so a pattern the UI accepts is one the scanner will actually compile, and a pattern that would be silently dropped at load time never reaches the config.parseAllowliststrims/lowercases domains, drops empties, dedupes, and throws on any unusable entry β a failed save leaves the existing config untouched.config-writerβ generalized to awriteConfigKeysmerge, pluswriteAllowlists. Allowlists keep insertion order (hand-curated, order carries intent);disabledRulesstays sorted for stable diffs. Every other key in the file is preserved.serverβPOST /save-allowlistsandPOST /validate-pattern, both token-checked like/save. Extracted a sharedreadJsonBodyhelper (body cap, content-type check, 400 on thrown validation errors) now that three routes need it. Startup output reports allowlist counts.pageβ Rules/Allowlists tabs with propertablist/tabpanelroles, add/remove per list, autosave, and live regex feedback while typing.dist/rebuilt.Testing
tests/allowlist-config-ui.test.tsadds 17 tests: pattern validation checked against what the scanner actually compiles, payload normalization/rejection, and the config writer preserving unrelated keys across both rule and allowlist saves.Full suite: 366 passing / 8 suites.
npm run lintandtsc --noEmitclean.Note: coverage is at the pure-function layer (
validate.ts,config-writer.ts) rather than HTTP-level β matching the existing convention, since/savehas no route tests either.