Skip to content

feat: Manage allowlists from the rules-picker UI - #46

Merged
fahadsiddiqui merged 1 commit into
mainfrom
feat/allowlist-config-ui
Jul 23, 2026
Merged

feat: Manage allowlists from the rules-picker UI#46
fahadsiddiqui merged 1 commit into
mainfrom
feat/allowlist-config-ui

Conversation

@fahadsiddiqui

Copy link
Copy Markdown
Member

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) β€” validateAllowedPattern mirrors ScannerEngine.compileAllowedPatterns (parseable regex + safe-regex2 ReDoS 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. parseAllowlists trims/lowercases domains, drops empties, dedupes, and throws on any unusable entry β€” a failed save leaves the existing config untouched.
  • config-writer β€” generalized to a writeConfigKeys merge, plus writeAllowlists. Allowlists keep insertion order (hand-curated, order carries intent); disabledRules stays sorted for stable diffs. Every other key in the file is preserved.
  • server β€” POST /save-allowlists and POST /validate-pattern, both token-checked like /save. Extracted 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 β€” Rules/Allowlists tabs with proper tablist/tabpanel roles, add/remove per list, autosave, and live regex feedback while typing.
  • README β€” documents the two tabs, the validation, and the preserve-other-keys behavior.
  • dist/ rebuilt.

Testing

tests/allowlist-config-ui.test.ts adds 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 lint and tsc --noEmit clean.

Note: coverage is at the pure-function layer (validate.ts, config-writer.ts) rather than HTTP-level β€” matching the existing convention, since /save has no route tests either.

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.
@fahadsiddiqui fahadsiddiqui changed the title feat: manage allowlists from the rules-picker UI feat: Manage allowlists from the rules-picker UI Jul 23, 2026
@fahadsiddiqui
fahadsiddiqui merged commit aed58b4 into main Jul 23, 2026
3 checks passed
@fahadsiddiqui
fahadsiddiqui deleted the feat/allowlist-config-ui branch July 23, 2026 07:34
@fahadsiddiqui
fahadsiddiqui restored the feat/allowlist-config-ui branch July 23, 2026 07:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Rules-picker UI only toggles rules β€” no way to configure allowedDomains/allowedValues/allowedPatterns

1 participant