Skip to content

fix(github): devops gh api masks a token in a JSON reply together with the closing quote, so the output is not valid JSON #2569

Closed

Description

@dan-petty

Problem Description

devops gh api masks secrets in the reply it prints, and the mask breaks a JSON reply. A contents reply (GET repos/<owner>/<repo>/contents/<path>) of a private repository has a download_url that holds a token= query parameter. The printed reply replaces the token value and the closing quote of the string with <masked-token>, so the output is no longer valid JSON. Each caller that parses the output with json.load fails with JSONDecodeError: Expecting ',' delimiter.

Reproduction Steps

  1. Run uv run devops gh api "repos/<owner>/<private-repo>/contents/<file>" > out.json.
  2. Run python3 -c "import json; json.load(open('out.json'))".

Expected vs Actual Behavior

  • Expected: the masked output is valid JSON: the mask replaces only the secret characters inside the string, and the quotes stay.
  • Actual: the output holds ...?token=<masked-token>,"type":"file",...: the closing quote of download_url is gone, and json.load fails at that position.

Environment Diagnostics

  • devops-cli on origin/main 9e73e6d (2026-10-28).

Logs, Traces, or Terminal Output

json.decoder.JSONDecodeError: Expecting ',' delimiter: line 1 column 595 (char 594). A regex read of the content field still works, so only a caller that parses the whole reply fails.

Existing Tool Considered

The masking already exists (security/sanitizer.py). The fix is in its pattern for a query-string token: stop the match at a quote. Nothing new is built.

Proposed design

Problem statement

The devops gh api command masks secrets in its printed reply. When a JSON reply contains a token= query parameter, the mask regex also consumes the closing quote of the JSON string. The output is no longer valid JSON, and any caller that parses it with json.load fails with a JSONDecodeError.

Acceptance criteria

Requirement: Mask preserves JSON quotes

The mask SHALL replace only the secret characters of a token value and SHALL NOT consume the closing quote of the enclosing JSON string.

Scenario: JSON reply with token in download_url

  • WHEN A JSON reply contains "download_url":"https://...?token=SECRET123" and the sanitizer masks the token
  • THEN The output contains "download_url":"https://...?token=" and json.loads succeeds on the full output

Requirement: Bare token still masked

The mask SHALL still replace a token value that appears outside a quoted JSON string.

Scenario: Bare token in plain text

  • WHEN The output contains token=SECRET456 with no surrounding quotes
  • THEN The output contains token=

Requirement: Single-quote strings preserved

The mask SHALL NOT consume a single-quote character that closes a string.

Scenario: Single-quoted string with token

  • WHEN The output contains 'download_url':'https://...?token=SECRET789'
  • THEN The output contains 'download_url':'https://...?token='

Existing Tool Considered

The masking logic already exists in security/sanitizer.py. The fix is a one-line change to the regex pattern for a query-string token: stop the match at a quote character. No new code is built. The written cost is the tokens to edit one regex, add one test case, and fix the pattern until it matches the expected output, plus the elapsed time of one short session.

Key questions

  • What is the correct fix to the regex?: Add quote characters to the excluded set of the token-value match. Change the pattern so the token value stops at a double-quote or single-quote. For example, change token=[^&\s]+ to token=[^&\s"']+. This preserves the quote while still masking the secret. (proposed)
    • Chosen: Exclude quotes from the token-value character class. Stops the match at the quote. Minimal change. Preserves both single and double quotes. Chosen.
    • Rejected: Use a negative lookahead for the quote. More complex. Same result as excluding the quote from the character class. No advantage.
    • Rejected: Post-process the masked string to re-insert the quote. Adds a second pass. More code to maintain. The regex fix is simpler and correct.

Open questions

  • What is the current regex pattern in the sanitizer that matches a query-string token? (missing verified source)
  • Does the same pattern appear elsewhere in the codebase? (missing verified source)

Fit

Fits in one pull request.

Suspected block

None.

Dependencies

None.

Alternatives check of 2026-11-04: none.
Tool: none found.

Activity

  1. added
    source/agent
    type/bug
    status/new
    value/medium
    effort/low
    on Oct 29, 2026
  2. dan-petty commented on Oct 29, 2026

    @dan-petty
    OwnerAuthor

    Intake placed this item to the backlog: intake puts every new item in the backlog. A person plans the milestones.

    • Type: type/bug. The mask swallows a closing quote and breaks valid JSON output, which is a correctness defect.
    • Priority: P2-Medium. It breaks JSON parsing for private-repo callers but a regex workaround exists, so it is not blocking.
    • Value: Medium. Callers that parse the full reply with json.load fail, but a partial workaround is available.
    • Effort: Low. The fix is a single regex change to stop the token match at a quote character.
    • Related: fix(security): a credential value is masked also when the next line starts with a parenthesis #2471, which asks for a different change. Both fix a regex boundary bug in security/sanitizer.py, but 2471 stops a lookahead from crossing a line break while the candidate stops a match from consuming a quote.
  3. added
    priority/p2-medium
    on Oct 29, 2026
  4. devops-cli-service commented on Oct 29, 2026

    @devops-cli-service
    Contributor

    Refine cannot set this item to Ready at a3eb41f until a person answers the questions below. Reply in a comment or edit the body, and the next refine round looks at the item again.

    • What is the current regex pattern in the sanitizer that matches a query-string token? (missing verified source)
    • Does the same pattern appear elsewhere in the codebase? (missing verified source)
  5. added
    scope/github
    on Oct 30, 2026
  6. devops-cli-service commented on Nov 4, 2026

    @devops-cli-service
    Contributor

    Alternatives check: none

    Tool: none found

    Lacks:

    • No searched tool fixes the actual defect: the query-string token regex in the project's own security/sanitizer.py must stop at a quote so the mask keeps the closing quote of a JSON string.
    • JSON masking libraries found mask by JSON key/field on structured objects (e.g. a configured set of keys and value maskers), not a token= query parameter embedded in an already-serialized JSON string.
    • Log-redaction filters replace whole regex matches in text, which is the same behaviour that swallows the closing quote, so they would need the same boundary fix rather than replacing the project's sanitizer.

    Searches run:

    • python library mask secrets in JSON output keeping valid JSON
    • python redact sensitive tokens from log text regex library
    • library sanitize secrets in JSON string values preserving valid JSON structure masking

    Sources:

    Checked on 2026-11-04. A person decides what this means for the item. The check changes no label and closes no issue.

  7. added
    status/in-progress
    status/in-review
    and removed
    status/new
    status/in-progress
    on Nov 5, 2026
  8. removed
    status/in-review
    on Nov 5, 2026
  9. devops-cli-service commented on Nov 5, 2026

    @devops-cli-service
    Contributor

    Live since 2026-11-05 20:49 UTC

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    effort/lowpriority/p2-mediumscope/githubsource/agenttype/bugvalue/medium

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions