feat(assessment): find the attempt behind a leaked task text
This commit is contained in:
1 parent
bb917bf62e
commit
5a731c25b7
26 files changed
+2500
No files matched your search
@@ -725,6 +725,16 @@ Implemented for real attempts (root and corrective). A training run (`demo_expre
|
||||
- Limits of the rule. It is a one-page-at-a-time rule, not a security boundary: a client that never holds the session is refused only while another page holds it, a candidate can always continue after the hold is released or has expired, and two windows of one candidate are not told from two people. The hold is renewed by a page timer, so a browser that throttles a background tab to one tick a minute still renews within the two minutes.
|
||||
- Operator reading. `make -C backend assessment-review ARGS='inspect ...'` prints the new counts `extra_agents`, `client_screenshot_keys`, and `client_devtools_opens` next to the old ones; the note at its end repeats that browser signals can be forged and that a screenshot or a phone photo cannot be prevented or seen by the page.
|
||||
|
||||
### Leak trace
|
||||
|
||||
Implemented as a local operator command, `assessment-leak-trace`, that finds the real attempt behind a leaked task text. It reads text and nothing else: a screenshot or a photo must be read by an OCR tool first, and OCR itself is outside this project (the command accepts any UTF-8 text of at most 64 KiB from a file or standard input, and a visible code that the operator read by eye). The result is a hint for a manual review and an appeal. It is never shown to an employer (no HTTP operation serves it), it changes no score, category, or quota (the command writes nothing but its own audit), and it never names an attempt on a guess. Code: `backend/cmd/assessment-leak-trace/`, `backend/internal/adapter/primary/cli/leaktrace/command.go`, `LeakTracer` in `backend/internal/usecase/assessment/leak_trace.go`, `AssessmentLeakAlignment` and `AssessmentTextPiecesBetweenPhrases` in `domain/assessment_wording.go`, `domain/assessment_leak_trace.go`, migration `backend/db/migrations/00051_create_assessment_leak_traces.sql`, and the queries `backend/db/queries/assessment_leak_traces.sql`.
|
||||
|
||||
- Methods, strongest first. (1) The invisible mark: intact runs of zero-width characters decode to the code of an attempt (50 keyed bits), so one attempt behind one code is a finding on its own. (2) The visible code: the code of the tile, found in the text of a screenshot as two groups of five characters (or ten characters followed by the date and time of the tile) or given with `--code`; one character that the recognizer misread is tolerated (45 bits), two are not. The time on the tile is compared with the life of the attempt (an hour of slack) and reported as a note, never as a verdict, because it is the clock of a device. (3) The statement and its wording: the stored, unmarked statements of real attempts are searched for pieces of the text, the attempts that were served that statement are told apart from other variants of the same family by how far the text follows their statement, and among those by the phrase forms the text shows (about one bit per phrase group; only the phrases aligned with the stored statement are read, so words around the statement in a message are ignored). A statement counts only when the text is a copy of it, whole or cut where the text stops: other words where the statement continues mean that another variant of the same family, which shares only its fixed text, is not the source. A statement text that only one attempt was served names that attempt by the variant alone when the text shows no phrase group, and is excluded when the text shows phrases that contradict the attempt, because the leak may come from an attempt that was deleted.
|
||||
- The code of an attempt is computed, never stored, so no lookup table exists: the command walks every real attempt (5000 per page), computes its code from `IDENTITY_KEY_SECRET`, and compares. The work is linear in the number of attempts and fine for an operator command. The command therefore needs the secret of the server that served the attempts; a rotated secret makes older codes and marks unreadable, and then the search can still use the statement text.
|
||||
- Outcomes. `found` names one attempt, the method, and the strength in bits, with notes such as whether the statement text matches the attempt (a mark attached to another text is flagged). `ambiguous` means that the evidence leaves several attempts in play (two attempts behind the codes, a mark and a visible code that name different attempts, or attempts that were served the same statement and chose the same phrases) and names none. `not_found` is an honest answer when the data is not enough: no mark, no code, no stretch of at least 24 characters free of interchangeable phrases, no statement that contains the text, a text that more than 200 statements contain (generic), or a wording that contradicts every holder.
|
||||
- Audit. Every search writes one row to `assessment_leak_traces` in the same transaction as the search, before a result is printed: the operator handle (`operator:<handle>`, not authentication), the database time, a keyed digest of the normalized text (HMAC-SHA-256 under a key derived from `IDENTITY_KEY_SECRET`, label `lincodex/assessment/leak-text/v1`), its length, the outcome, the method, the attempt for a found search, and the counts. The text is never stored or printed, the table refuses UPDATE, DELETE, and TRUNCATE, and the attempt is not a foreign key, so the audit outlives an account deletion. Rolling migration 51 back is refused while the audit holds a row.
|
||||
- What it cannot do. A leak with the mark and the tile gone, retyped in own words, or photographed so that no tile is legible leaves only the wording and the variant, which name one attempt only when few attempts were served the same statement. The text of a screenshot depends on the OCR tool. A text that was edited breaks the alignment. A watermark cannot prevent a leak, and the result is evidence for a person, not a decision. The command and its audit are described in [Operating the leak trace](DEPLOY.md#leak-trace).
|
||||
|
||||
### Skill evidence
|
||||
|
||||
Implemented as a stored projection of the immutable assessment results, with two reads: the candidate's own list and the permitted projection of a currently visible card. The match search reads the organization projection (see [Matching and explanations](#matching-and-explanations)); no percentile reads it yet.
|
||||
|
||||
@@ -445,6 +445,23 @@ make -C backend assessment-review ARGS='inspect --attempt <uuid> --actor operato
|
||||
- To use thresholds other than the demo values, publish a policy version with an `assessment.signals` section through the policy publisher. `DemoProductPolicyV3` is the demo example and is published only explicitly (the isolated browser fixture does so); the startup seed publishes version 1 only. Attempts that already started keep the version they started with. The demo duplicate thresholds assume a population: a copied pair is flagged only from about 26 answers per family (attention) and 61 (review) at 13 items, or 9 and 14 at 23 items. To try the feature on a smaller stand, publish a policy version with lower `duplicate_bits_attention` and `duplicate_bits_review` (the integration tests use 4 and 6); do not edit the demo policy. A review is a point-in-time evaluation, run again by the job at the deadline. The job logs one line per run with the number of reviews and its duration (`assessment review job finished`).
|
||||
- The rows hold counts, durations, and keyed digests (HMAC-SHA-256 under keys derived from `IDENTITY_KEY_SECRET`, each with a key version) and no answer text. Rotating the secret keeps the stored rows but makes new fingerprints incomparable with old ones. Deleting an account deletes its attempts and, by cascade, their facts and reviews; the audit rows keep only the attempt ID and the handle. The digests are kept for the lifetime of the attempt; no retention period is defined yet.
|
||||
|
||||
## Leak trace
|
||||
|
||||
An operator finds the attempt behind a leaked task text with a local command (see [ARCHITECTURE.md](ARCHITECTURE.md#leak-trace) for how it decides). It takes text; a screenshot has to be read by an OCR tool first, which is not part of this project:
|
||||
|
||||
```sh
|
||||
make -C backend assessment-leak-trace ARGS='search --actor operator:<handle> --file leaked.txt'
|
||||
pbpaste | make -C backend assessment-leak-trace ARGS='search --actor operator:<handle> --stdin'
|
||||
make -C backend assessment-leak-trace ARGS='search --actor operator:<handle> --code 7K3QD-9XM2T'
|
||||
```
|
||||
|
||||
- The command needs `DATABASE_URL` and `IDENTITY_KEY_SECRET`, and reads nothing else from the environment or a dotenv file. The secret must be the one of the server that served the attempts: the codes and marks are computed from it, so a different secret finds nothing, and the command refuses an unset, placeholder, or short secret and never prints it. `make -C backend assessment-leak-trace-build` builds `backend/bin/assessment-leak-trace`.
|
||||
- Put the text in a file or on standard input, not in a command-line argument, so that it stays out of the shell history and the process list. The text is at most 64 KiB of UTF-8; a longer one is refused, and a document can be searched in pieces. `--code` takes a visible code that was read from a screenshot by eye, with or without the hyphen and in either case.
|
||||
- It prints the search ID, `found`, `ambiguous`, or `not_found`, and for a found search the method (`invisible_mark`, `visible_code`, `wording`, or `variant`), the attempt ID, and the strength in bits, with notes that never quote the text. `not_found` is a normal outcome, not an error: the data was not enough to name an attempt.
|
||||
- Every search is recorded in `assessment_leak_traces` (operator handle, database time, a keyed digest and the length of the text, the outcome, the method, the attempt of a found search, and counts) before a result is printed, whatever it finds. The table refuses UPDATE, DELETE, and TRUNCATE, keeps no text, and outlives the attempt it names. The handle is an audit label, not authentication: any holder of the database credential can type any handle. Rolling migration 51 back is refused while the audit holds a row.
|
||||
- The result goes to the operator only. No HTTP operation serves it, an employer never sees it, and it changes no score, category, or quota. It is a hint for a manual review and an appeal, not a decision.
|
||||
- The command reads every real attempt to compute its code and searches the stored statements, so it is meant for an operator and not for a request path; its cost grows linearly with the number of attempts.
|
||||
|
||||
## Demonstration categories on a stand
|
||||
|
||||
A category from a `demo_basic` result is assigned only on an isolated synthetic stand. It is not calibrated and must not appear in an environment with real candidates. Two independent steps enable it on a stand:
|
||||
|
||||
@@ -558,6 +558,10 @@ Over HTTP with PostgreSQL. `TestAssessmentWorkSessionOverHTTP` creates a real at
|
||||
|
||||
Frontend. Vitest covers the key rules (`capture-keys.test.ts`), the heuristic and its watcher with fake windows and timers (`devtools-heuristic.test.ts`), the collector (one event for a press and its release, no cancelling, no event without an item), the session wiring of the watcher, the work session controller (held, busy, lost at a renewal, a network gap, a release during a renewal, the renewal bounds, `work-session.test.ts`), the page identifier header of the answer command, and the notice version 4 text. `e2e/assessment-capture.spec.ts` runs against the mocked API (also on the Vite server, `E2E_BASE_URL=http://localhost:5173 pnpm exec playwright test e2e/assessment-capture.spec.ts --project=chromium`): PrintScreen and Cmd+Shift+4 are recorded as `screenshot_key` events with no key or image, the key event is not cancelled and the test goes on to an answer; a faked docked panel is recorded as `devtools_open`; a second tab opened on the attempt is refused with the explanation and shows no task, nothing is started in it, the first tab is undisturbed, and after the first tab leaves the second continues; `pagehide` releases the session; a tab that loses the session at a renewal stops and says so. These tests do not show behavior in other browsers or on a phone, whether the operating system hands a shortcut to the page, what a real screenshot looks like, or how often the heuristic is wrong on real windows; the mock server stands for the rules of the real one, which the HTTP test covers.
|
||||
|
||||
## Assessment leak trace tests
|
||||
|
||||
`backend/internal/usecase/assessment/leak_trace_test.go` runs the tracer against in-memory repositories with real watermarks: the leaked text of a variant, among other words, finds the right one of three attempts that were served the same statement (by the invisible mark); with the invisible characters removed, the visible code of the tile text finds the attempt, and the wording alone separates the attempts that were served the same statement and chose different phrases; the visible code tolerates one misread character and not two; unrelated text, a text that is too short, and a mark of no attempt are not found and say why; a statement that only one attempt holds is found by the variant and excluded when its wording contradicts the text; attempts that chose the same phrases, or a text with no phrase group, are ambiguous without naming one; a mark attached to another text is found and flagged; a mark and a visible code that name different attempts are ambiguous; another variant of the same family does not compete with the leaked one, and the leak of a deleted attempt is not attributed to the variant of its family that is left; a leak cut inside the statement is found, while other words where the statement continues are not; every search is audited with a keyed digest and no part of the text, the same text gives the same digest, and a failed audit fails the search; bad requests are refused without quoting the text. `domain/assessment_watermark_test.go` covers the alignment and the wording agreement (only the phrases aligned with the stored statement are read, a fragment, unrelated text, another variant aligning for fewer characters), `domain/assessment_leak_trace_test.go` the audit record, `usecase/identity/keyring_test.go` the keyed text digest, `config/identity_test.go` the secret reader, and `adapter/primary/cli/leaktrace/command_test.go` the argument rules, the file and standard input reading with its limit, the output (the outcome and fixed notes, never the text, an honest not found), safe error messages, and that the environment is not read before the arguments are valid. `TestAssessmentLeakTraceOverHTTP` (PostgreSQL) creates two real attempts over HTTP and checks that the marked prompt finds the first by its mark, the prompt without invisible characters finds the second by its statement, the text of a screenshot with the tile finds the first by its visible code and the tile time, unrelated and short text are not found, a search changes no attempt version or state and no review or result, every search is audited without the text, the audit refuses UPDATE, DELETE, and TRUNCATE and a found row without an attempt, the audit outlives a deleted attempt (which is then not found), and the command with the secret of the server finds the attempt while one with another secret does not read the mark. They do not run an OCR tool, so what the command does with the real recognition errors of a screenshot, and how well the wording separates attempts on a real bank, are not measured here.
|
||||
|
||||
## Internal notification tests
|
||||
|
||||
Unit tests (`make -C backend test`, `make -C frontend test`):
|
||||
|
||||
Reference in new issue
Block a user