Skip to content

Deduplicate ASCII validation and cluster JSON Pointer helpers - #17113

Merged
lpcox merged 2 commits into
mainfrom
copilot/refactor-duplicate-isascii-helper
Nov 23, 2026
Merged

lpcox merged 2 commits into
mainfrom
copilot/refactor-duplicate-isascii-helper

Conversation

@lpcox

@lpcox lpcox commented Nov 22, 2026 •

Copy link
Copy Markdown
Collaborator

ASCII validation was duplicated across selector validation and sanitization, while applyIfConfigured lived in production code despite having only test callers. JSON Pointer escaping and decoding were also split across files.

  • Shared ASCII validation: Add util.IsASCII, replace both private copies, and cover control bytes, Unicode, and invalid UTF-8.
  • Test-only wrapper: Move applyIfConfigured into test code; leave production middleware unchanged.
  • JSON Pointer cohesion: Colocate escaping and splitting in one file, preserving existing semantics and adding escape-order and round-trip coverage.

Distinct normalization and redaction policies remain separate.

@lpcox lpcox changed the title [WIP] Refactor duplicate isASCII helper and test wrapper in production code Deduplicate ASCII validation and cluster JSON Pointer helpers Nov 22, 2026
@lpcox
lpcox marked this pull request as ready for review November 23, 2026 00:13
Copilot AI adaptive review requested due to automatic review settings November 23, 2026 00:13

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 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 applyIfConfigured into 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)

@github-actions

Copy link
Copy Markdown
Contributor

🔒 mcpg Read-Only Stress — default

Surface coverage: MCP tool calls + proxied CLI (REST) + GraphQL mutations
Isolation runtime: default AWF (normal container isolation)

Part Surface Op Result Expected Status
A MCP reads (list_issues, list_pull_requests, get_file_contents, list_commits) data returned ALLOWED ✅
B MCP writes (add_issue_comment/star_repository/issue_write/create_branch/create_or_update_file/create_pull_request) all 6 tools absent from 23-tool catalog BLOCKED ⚠️
C CLI reads (same 4 ops via proxied github CLI) data returned ALLOWED ✅
D CLI REST writes (reaction/star/issue/comment) not attempted — gh unauthenticated BLOCKED ⚠️
E CLI GraphQL mutations (addReaction/addStar/createIssue) not attempted — gh unauthenticated BLOCKED ⚠️

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 GITHUB_READ_ONLY=1) but does not independently exercise the gateway's own DIFC/guard write-blocking layer. Parts D/E could not run because gh auth status reports 'You are not logged into any GitHub hosts' in this environment — no REST/GraphQL write attempts were made. No reaction, star, issue, comment, branch, file, or PR was created.

🔒 mcpg read-only stress (default AWF runtime) by Read-Only Stress: default runtime

@lpcox
lpcox merged commit 889d28a into main Nov 23, 2026
37 checks passed
@lpcox
lpcox deleted the copilot/refactor-duplicate-isascii-helper branch November 23, 2026 00:25
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.

[refactor] Semantic function clustering: duplicate isASCII helper and test-only wrapper in production code

3 participants