Standard production layout: the OKR app (was nested under AINative_OKR_CASAN5/) is now
the repository root. No more wrapper directory.
- Promote AINative_OKR_CASAN5/* -> repo root (backend/ frontend/ packages/ apps/
.specify/ docs/ infra/ nginx/ scripts/ + configs). Merge tool dirs: .gitea (kept the
active deploy ci.yml, added harness-ci.yml + runbooks), .claude (agents/commands +
launch.json), .github moved up.
- Remove redundant: 00_SUBMISSION_PACKAGE, scattered root notes (FPT_CASAN_Full.md,
tu-tuong-casan.md, casan-tu-sinh..., casan_harness_assessment.md, source-review...,
README_CASAN5_REFINED.md), casan-next-plans/ and optimize-docs/ (competition/planning
artifacts — roadmap + design history preserved in git log / commit messages).
- Update all references to the old layout:
- .gitea/workflows/{ci,harness-ci}.yml, .github/workflows/{ci,deploy}.yml:
working-directory .; drop AINative_OKR_CASAN5/ prefix; .specify/{tests,scripts}
-> packages/casan-harness/... (.specify/logs state kept)
- .claude/launch.json, .gitea/*-runbook.md: path prefixes
- CLAUDE.md, README.md: docs/input -> apps/okr/domain/input
- policy-bundle.yaml: 8 policy paths -> packages/casan-harness/...; manifest re-signed
- secrets-scan.sh: fixture excludes -> new package/domain paths.
Full gate from the new root: PASS=64 FAIL=0 SKIP=3.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
63 lines
2.6 KiB
Python
Executable File
63 lines
2.6 KiB
Python
Executable File
#!/usr/bin/env python3
|
||
"""CASAN H4 — Unicode confusable / obfuscation normalizer (Track A, V3).
|
||
|
||
Reads text on stdin, writes a normalized variant on stdout used ONLY for
|
||
injection/jailbreak phrase matching (never for PII/secret redaction, so we
|
||
never widen what counts as a secret).
|
||
|
||
Deterministic transforms, in order:
|
||
1. NFKC compatibility normalization — folds fullwidth (ignore) and
|
||
other compatibility forms to their ASCII equivalents.
|
||
2. Strip zero-width / BOM / soft-hyphen formatting characters that split a
|
||
word so a blocklist never sees it (i·g·n·o·r·e).
|
||
3. Fold a fixed table of common Cyrillic/Greek homoglyphs to their Latin
|
||
lookalikes (іgnоrе -> ignore). NFKC does NOT do this — confusables are a
|
||
separate Unicode concern — so the table is explicit and auditable.
|
||
|
||
The table is intentionally small and covers the lookalikes actually used in
|
||
prompt-injection homoglyph attacks; extend it as new vectors appear.
|
||
"""
|
||
import sys
|
||
import unicodedata
|
||
|
||
# Zero-width, BOM, and invisible formatting code points.
|
||
ZERO_WIDTH = {
|
||
0x200B, # zero-width space
|
||
0x200C, # zero-width non-joiner
|
||
0x200D, # zero-width joiner
|
||
0x2060, # word joiner
|
||
0xFEFF, # BOM / zero-width no-break space
|
||
0x00AD, # soft hyphen
|
||
0x180E, # Mongolian vowel separator
|
||
0x2061, 0x2062, 0x2063, 0x2064, # invisible math operators
|
||
}
|
||
|
||
# Common Cyrillic / Greek homoglyphs -> Latin lookalike. Lowercase and
|
||
# uppercase both listed because matching is case-insensitive downstream but the
|
||
# fold must run before case handling to be safe.
|
||
CONFUSABLES = {
|
||
# Cyrillic lowercase
|
||
"а": "a", "е": "e", "о": "o", "р": "p", "с": "c", "у": "y", "х": "x",
|
||
"ѕ": "s", "і": "i", "ј": "j", "ԁ": "d", "һ": "h", "ӏ": "l", "п": "n",
|
||
"г": "r", "т": "t", "к": "k", "м": "m", "в": "b",
|
||
# Cyrillic uppercase
|
||
"А": "A", "В": "B", "Е": "E", "К": "K", "М": "M", "Н": "H", "О": "O",
|
||
"Р": "P", "С": "C", "Т": "T", "У": "Y", "Х": "X", "Ѕ": "S", "І": "I",
|
||
"Ј": "J",
|
||
# Greek
|
||
"α": "a", "ε": "e", "ο": "o", "ρ": "p", "τ": "t", "ν": "v", "κ": "k",
|
||
"Α": "A", "Β": "B", "Ε": "E", "Ζ": "Z", "Η": "H", "Ι": "I", "Κ": "K",
|
||
"Μ": "M", "Ν": "N", "Ο": "O", "Ρ": "P", "Τ": "T", "Υ": "Y", "Χ": "X",
|
||
}
|
||
|
||
|
||
def normalize(text: str) -> str:
|
||
text = unicodedata.normalize("NFKC", text)
|
||
text = "".join(ch for ch in text if ord(ch) not in ZERO_WIDTH)
|
||
text = "".join(CONFUSABLES.get(ch, ch) for ch in text)
|
||
return text
|
||
|
||
|
||
if __name__ == "__main__":
|
||
sys.stdout.write(normalize(sys.stdin.read()))
|