Skip to content

Commit 5b172cd

Browse files
committed
Harden question_id validation with a strict identifier contract
Implement the change-note 13 deferred follow-up (reviewed contract, security_fix_review_publication_plan_20261023.md section 6): question ids now fullmatch \A[a-z0-9][a-z0-9_-]{0,63}\Z at the single authoritative boundary (_validate_question_record), reject-NOT-strip, enforced before dedup. Closes three hostile-id sinks with one rule: ':'-forgery of the 4-segment trace request-id shape, the strip/dedup collision that silently lost trace rows, and markdown table-row injection in gate-evidence reports. The stored value no longer strips (structurally redundant under the contract), so dedup and storage agree exactly. All 114 frozen synthetic_v1 ids satisfy the contract byte-identically; no corpus, hash, metric, or API change. New adversarial suite tests/eval/test_question_id_security.py (98 cases). Full suite 800 passed, 1 skipped, 1 warning (supersedes 702); Gate M1 reassessed: 5 passed / 4 blocked unchanged, no waivers. Docs: EVALUATION.md sections 2 and 7 document the rule; change note section 14 records it. README status correction rides here: the "question_id allowlist is not implemented" limitation is replaced with the implemented contract plus the standing third-party-data trust caveat, and the test record updates 702 -> 800 with the extended supersession chain.
1 parent 7d40909 commit 5b172cd

5 files changed

Lines changed: 496 additions & 13 deletions

File tree

‎RAG_Platform_Plan_Change_Note_v2.4.md‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,3 +216,16 @@ Documentation only. No application code, dependency files, lockfiles, benchmark/
216216
- **Commits (master):** `eacd8e5` C1 — Phases 4–6 + corpus (81 files; incl. the narrow `.gitignore` exception `corpora/*` + `!corpora/synthetic_v1/`, and a new one-rule `.gitattributes` `corpora/synthetic_v1/** -text` discovered necessary at staged review: under `core.autocrlf=true` without it, fresh checkouts re-mapped the corpus bytes and failed manifest SHA-256 verification on 6 PDFs (Windows) and would fail the 18 text files on `autocrlf=false` platforms — all 27 files verified byte-identical after simulated checkout). `c8f013c` C2 — Phase 7 (8 files; discloses that `cli.py` carries the fix's CLI hardening, so the security amendment spans C2+C3 under file-level grouping). C3 — Phase 8 + security amendment (20 files; this entry rides here).
217217
- **Disclosed limitation (Decision E):** file-level grouping means **C1 and C2 are not independently test-verified**; only the final published tree carries a recorded green run (702). No push occurred; remote publication remains a separate, unmade decision.
218218

219+
## 14. Addendum — `question_id` integrity hardening (2026-10-24)
220+
221+
**Date:** 2026-10-24
222+
**Scope:** Additive record of the `question_id` strict-identifier fix (the Decision-D deferral of §13.5, now implemented as a separately scoped change), its adversarial regression suite, and the Gate M1 reassessment. Sections 1–13 above are preserved unchanged; the canonical master plan was not modified; no earlier decision record was rewritten; no new D-number is created (D3, D10, D13–D18 remain pending). This entry rides the authorized Phase 8 closure commit of 2026-10-24 (owner-approved publication; SHA in `reports\phase8_publication_closure_20261024.md`).
223+
224+
**Fix — what changed and why (review basis: `reports\security_fix_review_publication_plan_20261023.md` §6):**
225+
1. **Root cause.** The question `id` had only a type + non-empty + per-file-dedup check. A hostile id could (a) forge extra `:` segments in the trace request-id `eval:<dataset_id>:<split>:<question_id>` (the exact class closed for `dataset_id`), (b) exploit the strip/dedup mismatch — dedup stored the raw value while the record stored the stripped value, so `"q1"` and `" q1 "` were "distinct" yet both became `q1`, colliding on the `traces.request_id` UNIQUE constraint whose violation is swallowed by best-effort tracing (silent evidence-row loss), and (c) inject markdown table rows (`\n|---|`, `|`) into gate-decision report artifacts. Rated Medium / integrity (no path sink, no SQLi, no crash path).
226+
2. **Fix (2 files).** `eval\dataset.py`: `_QUESTION_ID_PATTERN = \A[a-z0-9][a-z0-9_-]{0,63}\Z`, **fullmatch on the raw value, reject-NOT-strip**, enforced in `_validate_question_record` immediately after the type check and ahead of dedup — the single authoritative boundary (the only `Question` construction site in `src/`). The stored value no longer strips (now structurally redundant), so dedup and storage agree exactly and the collision class is closed. `docs\EVALUATION.md` §2 documents the rule as the contract; §7 notes the four-segment request-id shape is now structurally guaranteed.
227+
3. **Invariants preserved.** All 114 frozen `synthetic_v1` ids (dev 70 + test 44, `q0001`–`q0110`) satisfy the contract byte-identically — no corpus change, no hash change; valid-id ordering and determinism unchanged; cross-split id reuse stays legal (request ids differ by split); path-containment, dataset-integrity, redaction, and egress safeguards untouched; typed-error + safe-CLI conventions reused (`DatasetIntegrityError` → CLI exit 3, bounded message, no traceback).
228+
4. **Test record supersession** (each supersedes the last because changed code invalidated it): 641 → 696 → 702 → **800 passed, 1 skipped, 1 warning, exit 0 (39.22 s)** — lead-run 2026-10-24 (`.venv\Scripts\python.exe -m pytest -q`); new adversarial suite `tests\eval\test_question_id_security.py` **98 passed** (2.30 s); `tests\eval` 265 passed, 1 skipped; `tests\egress` + `tests\test_observer_trace.py` 18 passed, 1 warning; dataset-id security + frozen-corpus groups 61 passed. The 1 skip and 1 warning remain the pre-existing Windows symlink-privilege fixture and upstream `StarletteDeprecationWarning`. Defaults re-verified at runtime: `egress_mode='off'`, `local_generation_enabled=False`, `retrieval_score_floor=None`, `generation_model=None`.
229+
5. **Gate M1 reassessment (no status manufactured).** Reassessed criterion-by-criterion against fresh evidence: **unchanged at 5 passed / 4 blocked / 0 failed, no waivers** (checklist: `reports\question_id_hardening_20261024.md` §5). The question-id fix closes the §13.5 deferred follow-up but moves no gate criterion: criteria 1/5/7/9 stay blocked on the same D3/BG-1a/score-floor/perf-run prerequisites, and criterion 8's per-path instrumentation caveat is re-stated, not reinterpreted.
230+
6. **Prohibition status.** The §13 "non-self-authored datasets must not be evaluated until the allowlist lands" restriction is **satisfied for the identifier-integrity dimension** by this fix. The separate trust caveat is unchanged and still binding: the corpus remains same-author (R19 — hashes freeze self-consistency, not authorship), and no external-dataset evaluation is authorized by this entry.
231+

‎README.md‎

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ has not done as plainly as what it has. The header lists the nine stages every r
1111

1212
> [!NOTE]
1313
> **Where it stands:** all eight phases are committed (Phases 4–8 published 2026-10-23 in three commits, merged with
14-
> this README redesign). The lexical retrieval pipeline runs end to end through the API and CLI; generation is off by
15-
> default, so nothing writes text. Last full suite: **702 passed, 1 skipped, 1 warning**. Gate M1 is **not** passed
16-
> (5 passed / 4 blocked).
14+
> this README redesign, then hardened by the `question_id` integrity follow-up). The lexical retrieval pipeline runs
15+
> end to end through the API and CLI; generation is off by default, so nothing writes text. Last full suite:
16+
> **800 passed, 1 skipped, 1 warning**. Gate M1 is **not** passed (5 passed / 4 blocked).
1717
1818
[Architecture](#architecture) | [Status](#status-board) | [Inside the code](#inside-the-code) |
1919
[Run it](#run-it) | [Limits](#known-limits) | [Plan v2.4](RAG_Platform_Master_Plan_v2.4.md) |
@@ -166,9 +166,9 @@ The CLI shares the same pipeline:
166166
.venv\Scripts\python.exe -m rag_platform.cli eval --dataset corpora\synthetic_v1 --split dev
167167
```
168168

169-
Last full run, 2026-10-23: **702 passed, 1 skipped, 1 warning** (31.92 s) — the skip is the Windows symlink-privilege
169+
Last full run, 2026-10-24: **800 passed, 1 skipped, 1 warning** (39.22 s) — the skip is the Windows symlink-privilege
170170
fixture, the warning an upstream Starlette deprecation, both pre-existing. Record chain, each superseding the last as
171-
code changed: 641 (Phase 8, pre-fix) → 696 → **702**. Tests are hermetic: no network, no model load, fixtures under
171+
code changed: 641 (Phase 8, pre-fix) → 696 → 702 → **800**. Tests are hermetic: no network, no model load, fixtures under
172172
`data\tmp`. From any drive the two `D:`-layout tests fail by design. A `.env` file is optional; copy
173173
[`.env.example`](.env.example), which keeps egress off.
174174

@@ -225,12 +225,14 @@ data/ reports/ .cache/ gitignored runtime state
225225
- **Gate M1 is not passed: 5 passed / 4 blocked.** The blocked criteria — generation-enabled run, score-floor approval,
226226
the BG-1a verdict, and the generation-spike memory measurement — are recorded with reasons in the evidence checklist
227227
and change note §13; none is waived.
228-
- **`question_id` allowlist is not implemented.** Only self-authored, hash-frozen datasets may be evaluated. A
229-
non-self-authored dataset could forge `:`-delimited request ids or inject markdown rows; fix deferred pending owner
230-
approval (change note §13).
228+
- **`question_id` validation is implemented; third-party data is not approved by that fact.** Question ids now
229+
fullmatch a strict contract (`\A[a-z0-9][a-z0-9_-]{0,63}\Z`, reject-NOT-strip) at dataset load, closing request-id
230+
forgery, silent trace loss, and markdown-row injection (change note §14). That is an *identifier-integrity* control
231+
only: hashes freeze self-consistency, not authorship, so any dataset the project did not author must not be treated
232+
as approved until its use is separately reviewed.
231233
- **C1 and C2 are not independently test-verified.** The commits are grouped by file, so only the final tree carries a
232-
green run. The authoritative full-suite record is 702 passed / 1 skipped / 1 warning (2026-10-23); the chain 641 →
233-
696 → 702 each superseded the last as code changed.
234+
green run. The authoritative full-suite record is 800 passed / 1 skipped / 1 warning (2026-10-24); the chain 641 →
235+
696 → 702 → 800 each superseded the last as code changed.
234236
- **No benchmark numbers.** BG-1a has no valid result; the repo claims no throughput, latency, or quality figures.
235237
- **The 90 % RAM ceiling is a policy, not code.** The app can only refuse or stop its own work (plan §10.4).
236238
- **Windows and `D:` only.** Two tests assert the project lives on `D:` and fail anywhere else.
@@ -245,11 +247,10 @@ Committed so far: [`282cd11`](https://github.com/aspire488/rag-platform/commit/2
245247
[`247b899`](https://github.com/aspire488/rag-platform/commit/247b899) this README, then the three publication commits of
246248
2026-10-23: [`eacd8e5`](https://github.com/aspire488/rag-platform/commit/eacd8e5) phases 4–6 and the frozen corpus,
247249
[`c8f013c`](https://github.com/aspire488/rag-platform/commit/c8f013c) phase 7, [`88f023e`](https://github.com/aspire488/rag-platform/commit/88f023e) phase 8
248-
and the dataset-id security amendment.
250+
and the dataset-id security amendment — then, on 2026-10-24, the `question_id` integrity follow-up (change note §14).
249251

250252
| Remaining work | Unlocks |
251253
| --- | --- |
252-
| `question_id` allowlist (change note §13) | Safe evaluation of datasets the project did not author |
253254
| The four blocked Gate M1 criteria | A claimable Gate M1 |
254255
| BG-1a benchmark, owner-gated at the resource floors | The phase-6 generation verdict |
255256
| Milestones M2–M4 | Tenancy, evidence ledger, adaptive budget |

‎docs/EVALUATION.md‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,13 @@ CLI exit `3`):
5858

5959
- `type` ∈ {single-hop, multi-hop, unanswerable, conflict-aware,
6060
injection-adjacent}; `expected_outcome` ∈ {answer, abstain, flag-conflict};
61+
- **`id`**: strict identifier contract (change note 14) — full-string match on
62+
`\A[a-z0-9][a-z0-9_-]{0,63}\Z`, enforced at question load. Invalid ids are
63+
**rejected**, never stripped, normalized, truncated, or repaired. This
64+
structurally excludes `:` (request-id segment forgery), `/` and `\` (paths),
65+
whitespace/newlines/controls, `|` (markdown table-row injection), quotes,
66+
`%`, uppercase, and non-ASCII. All 114 frozen corpus ids satisfy it
67+
unchanged;
6168
- label rules: `answer` ⇒ non-empty gold set + gold answer; `abstain` and
6269
`unanswerable` ⇒ no gold; `gold_answer_span` must reference a gold chunk with
6370
`0 ≤ char_start < char_end`; IDs unique per file; ≤ 2000 chars per question;
@@ -170,6 +177,9 @@ printed in every report header (§9.4).
170177

171178
- Deterministic request IDs: `eval:<dataset>:<split>:<question_id>` — every
172179
report row links to its `traces`/`trace_stages` rows in the run database.
180+
The strict `id` contract (§2, change note 14) excludes `:` from question
181+
ids, so this shape is structurally guaranteed to stay exactly four segments
182+
— a hostile id can no longer forge extra segments.
173183
- Stage vocabulary (frozen in `observability.py`): retrieval ∈ {ok,
174184
no_candidates, insufficient_evidence}; context_build ∈ {ok, budget_invalid,
175185
budget_exhausted}. A query that abstains before context building honestly has

‎src/rag_platform/eval/dataset.py‎

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,16 @@
7575
# 64 - "eval_"(5) - (1 + len(split) + 1 + stamp(16) + 1 + hex(8))
7676
# -> dev 29 / test 28 for the dataset-id SEGMENT.
7777
MAX_DATASET_ID_CHARS = 32
78+
# Question-id contract (change note 14; reviewed in
79+
# reports/security_fix_review_publication_plan_20261023.md section 6).
80+
# Fullmatch on the RAW id, reject-NOT-strip: ':' / '/' / '\' / whitespace /
81+
# '|' / '%' / quotes / controls / uppercase / non-ASCII are all structurally
82+
# excluded, so one regex closes every hostile-id sink - request-id segment
83+
# forgery in eval:<dataset_id>:<split>:<question_id>, the strip/dedup
84+
# collision that silently lost trace rows, and markdown table-row injection
85+
# in gate-evidence reports. The 64-char cap mirrors the dataset-id grammar
86+
# so both variable segments of the request id stay bounded.
87+
_QUESTION_ID_PATTERN = re.compile(r"\A[a-z0-9][a-z0-9_-]{0,63}\Z")
7888

7989

8090
class DatasetIntegrityError(Exception):
@@ -421,6 +431,13 @@ def _validate_question_record(
421431
question_id = item.get("id")
422432
if not isinstance(question_id, str) or not question_id.strip():
423433
raise DatasetIntegrityError(f"{context}: id must be a non-empty string")
434+
# Strict identifier contract (change note 14): fullmatch on the raw
435+
# value, reject-NOT-strip - a hostile id is refused outright, never
436+
# silently normalized, truncated, or repaired.
437+
if _QUESTION_ID_PATTERN.fullmatch(question_id) is None:
438+
raise DatasetIntegrityError(
439+
f"{context}: id must match {_QUESTION_ID_PATTERN.pattern}"
440+
)
424441
if question_id in seen_ids:
425442
raise DatasetIntegrityError(f"{context}: duplicate question id {question_id!r}")
426443
q_context = f"{context} id={question_id!r}"
@@ -503,7 +520,10 @@ def _validate_question_record(
503520
raise DatasetIntegrityError(f"{q_context}: structures must be a string list")
504521
seen_ids.add(question_id)
505522
return Question(
506-
question_id=question_id.strip(),
523+
# The strict id contract above rejects surrounding whitespace, so
524+
# the stored value is byte-identical to the manifest value - no
525+
# strip, no normalization (change note 14).
526+
question_id=question_id,
507527
type=q_type,
508528
expected_outcome=outcome,
509529
question=question,

0 commit comments

Comments
 (0)