Repository navigation
Deduplicate ASCII validation and cluster JSON Pointer helpers - #17113
Conversation
Co-authored-by: copilot-swe-agent[bot] <[email protected]>
There was a problem hiding this comment.
🔵 Needs a closer look
Human confirmation is warranted because the refactor jointly affects security-sensitive sanitization and selector paths, auth test infrastructure, and DIFC JSON Pointer canonicalization across packages, creating broad runtime and compatibility interactions.
No open issues 🎉
What changed in this PR
This pull request consolidates duplicated ASCII validation, moves a test-only middleware wrapper out of production code, and colocates JSON Pointer helpers while preserving existing behavior. No actionable issues were identified.
Changes:
- Added and tested shared
util.IsASCII, then updated sanitization and repository-selector validation to use it. - Moved
applyIfConfiguredinto test code while retaining production middleware behavior. - Consolidated JSON Pointer escaping and splitting helpers and added escape-order and round-trip tests.
| File | Description |
|---|---|
| internal/util/ascii.go | Adds the shared ASCII validation helper. |
| internal/util/ascii_test.go | Tests empty strings, control bytes, Unicode, and invalid UTF-8 inputs. |
| internal/server/middleware_auth.go | Removes the test-only middleware wrapper from production code. |
| internal/server/middleware_auth_test.go | Provides the middleware wrapper for server tests. |
| internal/sanitize/sanitize.go | Replaces the local ASCII implementation with util.IsASCII. |
| internal/reposelector/reposelector.go | Reuses util.IsASCII for repository-selector validation. |
| internal/difc/path_pointer.go | Colocates JSON Pointer escaping and splitting logic. |
| internal/difc/path_pointer_test.go | Adds JSON Pointer escape-order and round-trip coverage. |
| internal/difc/path_labels.go | Removes the duplicated JSON Pointer splitting implementation. |
| internal/difc/path_collections.go | Removes the duplicated JSON Pointer escaping implementation. |
Review effort: Lite (adaptive)
🔒 mcpg Read-Only Stress — defaultSurface coverage: MCP tool calls + proxied CLI (REST) + GraphQL mutations
Overall: INCONCLUSIVE No write leaked. Gaps: Part B's 6 write-tool targets are absent entirely from the gateway-exposed tool catalog (only 23 read-only tools registered), which confirms backend config (gh-aw forces
|
ASCII validation was duplicated across selector validation and sanitization, while
applyIfConfiguredlived in production code despite having only test callers. JSON Pointer escaping and decoding were also split across files.util.IsASCII, replace both private copies, and cover control bytes, Unicode, and invalid UTF-8.applyIfConfiguredinto test code; leave production middleware unchanged.Distinct normalization and redaction policies remain separate.