Skip to content

Latest commit

 

History

History
95 lines (67 loc) · 4 KB

redact.md

File metadata and controls

95 lines (67 loc) · 4 KB

redact.py

Revision: 1 Last modified: 2026-12-04T19:00:00Z

Overview

redact.py is the redaction gate for outgoing payloads (anchor §11.4.300(D)).

It scans a payload before any write and reports findings that carry a field name and a kind only — never the matched text.

That restraint is the whole design. A redactor that logged the secret it found, or echoed it into a finding, would leak the exact thing it exists to protect — into a log, a test fixture, a report, or a review comment. So the finding says "field title matched kind github-token", and never "field title contained ghp_…".

It also provides normalise, which strips zero-width and bidirectional control characters before scanning. That matters because a token split by an invisible character still reads as a token to a human and to GitHub, but not to a naive regex.

Prerequisites

  • python3 (standard library only: hashlib, re, unicodedata).
  • No network, no files.

Usage examples

from issue_sync import redact

# normalise first: strip zero-width / bidi controls that can split a token
clean = redact.normalise(raw_text)

# scan a payload; findings name the field and kind, never the matched text
findings = redact.scan(payload)       # UNCONFIRMED: exact scanner name
if findings:
    # refuse the write
    ...

UNCONFIRMED: the precise scanner entry-point name was not read while writing this guide. Inspect the module before depending on one: python3 -c "import issue_sync.redact as r; print([n for n in dir(r) if not n.startswith('_')])".

Exported surface

Name Kind Contract
normalise(text) function Strips zero-width and bidirectional control characters (U+00AD, U+200B–U+200F, U+202A–U+202E, U+2060–U+2064, U+FEFF) so a split token is scanned as one token.
_ZERO_WIDTH regex The compiled character class normalise removes.

Scanner functions return findings containing field and kind only.

Exit codes

A library, so no exit codes. A finding causes the caller (payload.py's pre-write gate) to refuse the write, which surfaces to the CLI as the package's 1 (refused) or 2 (cannot determine).

Edge cases

  • A token split by a zero-width space. normalise rejoins it, so the scan sees one token.
  • Bidirectional override characters. Removed — they are a classic way to make a string display differently from its byte content.
  • A finding is reported. It carries field + kind only. The matched text never appears in the finding, the log or an error message.
  • A secret in a field that is not mirrored. The allowlist in payload.py already prevents it from being sent; redaction is a second, independent layer.
  • A near-miss (partial token). The conservative direction is to report; an unnecessary redaction is recoverable, an unnecessary publication is not.
  • Unicode normalisation forms. unicodedata is imported for that reason — a visually identical character sequence should not evade the scan.

Internal behaviour

  1. normalise(text) removes zero-width and bidi control characters.
  2. The scanner walks the payload's fields, applying the secret patterns to normalised text.
  3. For each match it records (field, kind) — never the matched substring.
  4. Returns the findings; the caller decides to refuse.

Related scripts

Imported by config.py, payload.py and (transitively) engine.py, cli.py, pipeline.py.

Companion guard for inbound text: inbound.py (secret-scan with whole-text withholding) — a different policy for a different direction, both built on the same principle that untrusted text must not travel unexamined.

See also docs/scripts/payload.md, docs/scripts/inbound.md and docs/scripts/config.md.

Last verified

2026-12-04 — python3 -c "import ast;ast.parse(open('scripts/issue_sync/redact.py').read())" → exit 0. python3 -c "import issue_sync.redact as r; print(r.normalise('a\u200bb'))" prints ab (the zero-width space is removed).