Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion CAPABILITIES.md

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1 +1 @@
| Draft a system's write contract with a model at setup, admit it only by qualification: `openadapt verify draft` gives the pinned model (`claude-opus-5-5`, prompt digest recorded in the contract's `provenance`) the system's description (OpenAPI, GraphQL, FHIR CapabilityStatement, the introspected database schema, or none), one HAR trace with sign-in and secret fields masked, what that write moved in a sandbox, and the task. The draft is admitted only if, on the sandbox, it refutes planted faults (a wrong value in each written column, the wrong row, a duplicate, a sibling record edited, the write reverted after the check, and for an update another user's save overwritten through the app), confirms 5 clean writes and their rechecks, and confirms a two-users-by-two-payloads probe whose attribution of every moved column (values, user, clock, nothing) agrees with its bookkeeping exclusions. Failures go back to the model, at most 3 rounds; a person is asked at most once, only when a planted fault could go only into excluded columns. An admitted contract runs with no model calls; an edit to its check voids the admission (`--check`). Needs an SQL store the command can read and a privileged connection to plant faults | PR ([#2438](https://github.com/OpenAdaptAI/OpenAdapt/pull/2438)) | Real app, lab, synthetic data: Directus 11.5.1, never set up before: admitted in round 2 after 6.0 minutes with 0 person decisions (round 1 was lost because a sign-in fell inside the measured window; fixed after the run, not rerun), 7/7 planted faults refuted in admission and 8/8 held out (a lost update through the app among them), 0 false stops on 10 clean writes, 2 model calls. Mealie 2.8.0, never set up before: refused after 3 rounds in 9.2 minutes, since its store keeps no version, author or save history that could show a lost update. Synthetic MockLoan and workbench: admitted in round 1 in 1.3 to 1.4 minutes, 16/16 held-out faults. The pre-stated 5-minute limit on the untuned app was not met | `openadapt verify draft`, `openadapt_flow/verify_draft/`, [VERIFY_DRAFT.md](packages/flow/docs/VERIFY_DRAFT.md), [results](packages/flow/benchmark/verify_draft/RESULTS.md) |
| Draft a system's write contract with a model at setup, admit it only by qualification: `openadapt verify draft` gives the pinned model (`claude-opus-5-5`, prompt digest recorded in the contract's `provenance`) the system's description (OpenAPI, GraphQL, FHIR CapabilityStatement, the introspected database schema, or none), one HAR trace with sign-in and secret fields masked, what that write moved in a sandbox, and the task. The draft is admitted only if, on the sandbox, it refutes planted faults (a wrong value in each written column, the wrong row, a duplicate, a sibling record edited, the write reverted after the check, and for an update another user's save overwritten through the app), confirms 5 clean writes and their rechecks, and confirms a two-users-by-two-payloads probe whose attribution of every moved column (values, user, clock, nothing) agrees with its bookkeeping exclusions. Failures go back to the model, at most 3 rounds; a person is asked at most once, only when a planted fault could go only into excluded columns. An admitted contract runs with no model calls. Its admission record is signed with the local key, and `--check` refuses an edited check, an edited or unsigned record, or one no pinned key signed. Needs an SQL store the command can read and a privileged connection to plant faults | PR ([#2438](https://github.com/OpenAdaptAI/OpenAdapt/pull/2438)) | Real app, lab, synthetic data: Directus 11.5.1, never set up before: admitted in round 2 after 6.0 minutes with 0 person decisions (round 1 was lost because a sign-in fell inside the measured window; fixed after the run, not rerun), 7/7 planted faults refuted in admission and 8/8 held out (a lost update through the app among them), 0 false stops on 10 clean writes, 2 model calls. Mealie 2.8.0, never set up before: refused after 3 rounds in 9.2 minutes, since its store keeps no version, author or save history that could show a lost update. Synthetic MockLoan and workbench: admitted in round 1 in 1.3 to 1.4 minutes, 16/16 held-out faults. The pre-stated 5-minute limit on the untuned app was not met | `openadapt verify draft`, `openadapt_flow/verify_draft/`, [VERIFY_DRAFT.md](packages/flow/docs/VERIFY_DRAFT.md), [results](packages/flow/benchmark/verify_draft/RESULTS.md) |
2 changes: 1 addition & 1 deletion capabilities/CAPABILITIES.md.sha256
Original file line number Diff line number Diff line change
@@ -1 +1 @@
6df073cac92b3e1998b04f9e83520994614d253611d8f1f6597499ba8746651e
bfcb08bbcb1a926f732ed1dd15fc319cebbb2f38ae46f92d20e6e13edda3007a
489 changes: 290 additions & 199 deletions llms-full.txt

Large diffs are not rendered by default.

23 changes: 23 additions & 0 deletions packages/flow/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,29 @@

## Unreleased

- `openadapt verify draft` fix-forward for #2438. A clean admission case whose
recheck crashed (for example `database is locked`) now records the recheck
as `ERROR` and fails, instead of passing with no recheck. Trace and column
masking uses the shared token matcher in `openadapt_flow.secret_field_names`,
so `totp`, `otpCode`, `userPin`, `mfa_code`, a `cookie` key and the `code`,
`sig` and `X-Amz-Signature` query parameters are masked, and `author`,
`author_id` and `session_count` are not. The shared vocabulary gains
`token`, `jwt`, `bearer`, `credential(s)`, `cred`, `csrf`, `xsrf`,
`cookie`, `signature`, `session id`, `sessionid`, `private key`,
`access key`, `apikey`, `salt`, `hash`, `tfa`, `session key`,
`jsessionid`, `sessid`, `phpsessid`, `oauth verifier` and `authn`, plus
exact names (`code`, `sig`, `sid`, `refresh`, `session`, `authorization`)
and suffix names (`session`, `authorization`), so `JSESSIONID`,
`sso_session` and `proxy-authorization` stay masked as they were; the
Chrome extension copies follow. The earlier substring pattern stays as a
floor (so `sessionkey`, `pwdhash` and `authz` stay masked), with an
explicit list of false positives (`author`, `session_count`,
`authorization_id` ...) sent in clear. The admission
record is now signed with this computer's key, and `--check` refuses an
unsigned record, an edited record, or one no pinned key signed (`--keys`
pins another machine's key). `--check` no longer requires `--trace`,
`--task`, `--sandbox` and `--out`.

- Checkbox attestations (`openadapt_flow.gui.attestations`) are declared in
pack data with the digest of their statement and ticked only on an
`AttestationGrant` from the person who attests. A grant is its own type, so
Expand Down
26 changes: 25 additions & 1 deletion packages/flow/chrome_extension/content.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,31 @@
"access token",
"refresh token",
"secret",
"auth"
"auth",
"token",
"jwt",
"bearer",
"credential",
"credentials",
"cred",
"csrf",
"xsrf",
"cookie",
"signature",
"session id",
"sessionid",
"private key",
"access key",
"apikey",
"salt",
"hash",
"tfa",
"session key",
"jsessionid",
"sessid",
"phpsessid",
"oauth verifier",
"authn"
];
// secret-field-vocabulary:end
const SECRET_PHRASE_TOKENS = SECRET_FIELD_PHRASES.map((p) => p.split(' '));
Expand Down
26 changes: 25 additions & 1 deletion packages/flow/chrome_extension/network_redact.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,31 @@
"access token",
"refresh token",
"secret",
"auth"
"auth",
"token",
"jwt",
"bearer",
"credential",
"credentials",
"cred",
"csrf",
"xsrf",
"cookie",
"signature",
"session id",
"sessionid",
"private key",
"access key",
"apikey",
"salt",
"hash",
"tfa",
"session key",
"jsessionid",
"sessid",
"phpsessid",
"oauth verifier",
"authn"
];
// secret-field-vocabulary:end
const SECRET_PHRASE_TOKENS = SECRET_FIELD_PHRASES.map((p) => p.split(' '));
Expand Down
40 changes: 33 additions & 7 deletions packages/flow/docs/VERIFY_DRAFT.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,18 @@ to the model.
**One trace** (`--trace`). A HAR file of one correct demonstration of the
write. The command replays its write requests in the sandbox. Before anything
is sent to the model, it removes sign-in headers (`Authorization`, `Cookie`,
API-key headers) and masks fields whose names look secret (password, token,
key, session).
API-key headers) and masks fields, query parameters and headers whose names
look secret. Names are matched as whole tokens against the shared list in
`openadapt_flow/secret_field_vocabulary.json` (password, token, pin, otp,
totp, mfa, cookie, signature, session id, api key, ...), so `otpCode`,
`userPin` and `X-Amz-Signature` are masked while `author` and
`session_count` are not. A name that is exactly `code`, `sig`, `sid`,
`refresh`, `session` or `authorization` is masked too, and so is a name
that ends in `session` or `authorization` (`sso_session`,
`proxy-authorization`). The earlier substring pattern stays as a floor, so
compound names such as `sessionkey`, `pwdhash` and `authz` are masked too.
Only a short list of known false positives (`author`, `authority`,
`session_count`, `authorization_id` ...) is sent in clear.

**The task** (`--task`):

Expand Down Expand Up @@ -98,8 +108,9 @@ no reset hook.
time) are starting state and never land inside a write's window. The
sandbox then replays the trace's writes once, between two reads of the
store, to see which rows they move. The model gets the rows and columns
that moved, with their values, except a secret-named column (password,
token, secret, key, hash), whose value is masked. The sandbox holds
that moved, with their values, except a column with a secret name from
the same list (password, token, secret, api key, hash, ...), whose value
is masked. The sandbox holds
synthetic data only.
2. **Draft.** The pinned model writes a contract, as JSON text, that diffs
the whole database (`frame.database`). It also writes other valid values
Expand All @@ -121,7 +132,7 @@ no reset hook.
| `sibling_edit` | another business record edited beside the write | refuted |
| `late_revert` | the write undone after the check confirmed it | refuted at the recheck |
| `lost_update` | updates only: the other user saves the record first, then the agent's save overwrites it, both through the app | refuted, or prevented by the app |
| 5 clean writes | the write with other values, and a recheck of each | confirmed |
| 5 clean writes | the write with other values, and a recheck of each | confirmed (a recheck that crashes is an error, never a pass) |
| attribution probe | the write by two users with two sets of values (2 x 2), and the first of them again | confirmed |

A case the sandbox can't build is **untestable**, never a pass. Examples
Expand Down Expand Up @@ -182,9 +193,24 @@ window.
- `report.json`: admitted or not, rounds, person decisions, seconds and
model cost.

The admission record is signed with this computer's key (the key that signs
run receipts, under `~/.openadapt/seal` unless `OPENADAPT_SEAL_KEY` names
another). The signature covers the whole contract: the check, the inputs'
digests and the admission record. If the key can't be used, no contract is
written.

`openadapt verify draft --check contract.yaml` tells you whether the file is
still the check that was admitted. Any edit to its effects, its reads or its
frame after admission makes the check fail.
still the check that was admitted. The check fails when:

- the effects, reads or frame changed after admission;
- the admission record is not signed, or changed after it was signed;
- no pinned key signed it. By default the only pinned key is this computer's.
To check a contract admitted on another machine, pass that machine's key
with `--keys registry.json`, a JSON file of the form
`{"keys": [{"key_id": ..., "public_key": ..., "status": "active"}]}`.

This stops a forged or copied record. It does not stop someone who holds the
signing key.

## The model and its cost

Expand Down
27 changes: 23 additions & 4 deletions packages/flow/openadapt_flow/secret_field_names.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@
tokens against ``secret_field_vocabulary.json``. So ``patientSsn``,
``PatientSSN``, ``card_cvv``, ``card-cvv``, ``card.cvv`` and "Card CVV" all
match, while ``pinnedItems``, ``spinnerState`` and ``opinionText`` do not.
An identifier whose whole token list is one of ``exact_names`` (``code``,
``sig``, ``sid``, ``refresh``) is secret too, so ``code`` and ``Sig`` match
but ``productCode`` and ``refresh_interval`` do not. An identifier whose
last token is one of ``suffix_names`` (``session``, ``authorization``) is
secret, so ``sso_session`` and ``proxy-authorization`` match but
``session_count`` and ``authorization_id`` do not.

``chrome_extension/content.js`` and ``chrome_extension/network_redact.js``
implement the same ``fieldTokens`` split and embed the same phrase list; keep
Expand All @@ -20,12 +26,20 @@

_VOCABULARY_PATH: Final = Path(__file__).with_name("secret_field_vocabulary.json")

SECRET_FIELD_PHRASES: Final[tuple[str, ...]] = tuple(
json.loads(_VOCABULARY_PATH.read_text(encoding="utf-8"))["phrases"]
)
_VOCABULARY: Final = json.loads(_VOCABULARY_PATH.read_text(encoding="utf-8"))
SECRET_FIELD_PHRASES: Final[tuple[str, ...]] = tuple(_VOCABULARY["phrases"])
_PHRASE_TOKENS: Final[tuple[tuple[str, ...], ...]] = tuple(
tuple(phrase.split()) for phrase in SECRET_FIELD_PHRASES
)
#: Identifiers that are secret only when they are the whole name.
SECRET_EXACT_NAMES: Final[tuple[str, ...]] = tuple(_VOCABULARY.get("exact_names", ()))
_EXACT_TOKENS: Final[frozenset[tuple[str, ...]]] = frozenset(
tuple(name.split()) for name in SECRET_EXACT_NAMES
)
#: Identifiers that are secret when this is their last token.
SECRET_SUFFIX_NAMES: Final[frozenset[str]] = frozenset(
_VOCABULARY.get("suffix_names", ())
)

_LOWER_UPPER = re.compile(r"([a-z0-9])([A-Z])")
_ACRONYM_WORD = re.compile(r"([A-Z]+)([A-Z][a-z])")
Expand All @@ -41,9 +55,14 @@ def field_tokens(value: object) -> list[str]:


def names_secret_field(value: object) -> bool:
"""True when the identifier contains a secret phrase as whole tokens."""
"""True when the identifier contains a secret phrase as whole tokens,
is exactly one of the exact names, or ends in a suffix name."""

tokens = field_tokens(value)
if tuple(tokens) in _EXACT_TOKENS:
return True
if tokens and tokens[-1] in SECRET_SUFFIX_NAMES:
return True
for phrase in _PHRASE_TOKENS:
width = len(phrase)
for start in range(len(tokens) - width + 1):
Expand Down
40 changes: 38 additions & 2 deletions packages/flow/openadapt_flow/secret_field_vocabulary.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"schema": "openadapt.secret-field-vocabulary/1",
"description": "Secret field-name phrases for the Chrome extension redaction layers (content.js, network_redact.js, extension_evidence.py, extension_network.py). A field name, id, aria-label, autocomplete value or JSON key is split into lowercase tokens (camelCase and PascalCase boundaries, then any run of non-alphanumeric characters) and is secret when a phrase appears in it as whole consecutive tokens. content.js and network_redact.js embed an identical copy of this list; tests/test_extension_secret_field_names.py fails when they differ. 'code' alone is deliberately absent: only an identifier that is exactly 'code' is secret.",
"description": "Secret field-name phrases for the Chrome extension redaction layers (content.js, network_redact.js, extension_evidence.py, extension_network.py). A field name, id, aria-label, autocomplete value or JSON key is split into lowercase tokens (camelCase and PascalCase boundaries, then any run of non-alphanumeric characters) and is secret when a phrase appears in it as whole consecutive tokens. content.js and network_redact.js embed an identical copy of this list; tests/test_extension_secret_field_names.py fails when they differ. 'code' alone is deliberately absent from phrases: an identifier is secret when its whole token list is one of exact_names ('code', 'sig', 'sid', 'refresh'), so code and Sig are secret but productCode and refresh_interval are not. An identifier whose last token is one of suffix_names ('session', 'authorization') is secret too, so sso_session, x-session and proxy-authorization are secret, while authorization_id is not. Bare 'session' and 'key' are not phrases, so session_count and record_key stay clear. content.js and network_redact.js embed the phrases only; their own patterns cover the exact and suffix names.",
"phrases": [
"password",
"passwd",
Expand Down Expand Up @@ -33,6 +33,42 @@
"access token",
"refresh token",
"secret",
"auth"
"auth",
"token",
"jwt",
"bearer",
"credential",
"credentials",
"cred",
"csrf",
"xsrf",
"cookie",
"signature",
"session id",
"sessionid",
"private key",
"access key",
"apikey",
"salt",
"hash",
"tfa",
"session key",
"jsessionid",
"sessid",
"phpsessid",
"oauth verifier",
"authn"
],
"exact_names": [
"code",
"sig",
"sid",
"refresh",
"session",
"authorization"
],
"suffix_names": [
"session",
"authorization"
]
}
20 changes: 17 additions & 3 deletions packages/flow/openadapt_flow/verify_draft/admit.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
)
from openadapt_flow.verdict_sites import verdict_site
from openadapt_flow.verifier import Outcome
from openadapt_flow.verify_draft.inputs import SECRET_NAME_RE
from openadapt_flow.verify_draft.inputs import is_secret_name
from openadapt_flow.verify_draft.sandbox import (
App,
Move,
Expand Down Expand Up @@ -160,7 +160,16 @@
"server_set",
}
)
_SECRET_COLUMN = SECRET_NAME_RE


def _secret_column(column: str) -> bool:
"""A column whose values the model never sees. A column named just
``code`` is an ordinary identifier here (see ``_IDENTIFIER``), unlike a
query or form key named ``code``."""

return is_secret_name(column) and column.strip().lower() != "code"


_IDENTIFIER = re.compile(r"(^|_)(id|key|no|number|code|slug|mrn|ref|uuid)$", re.I)


Expand Down Expand Up @@ -341,7 +350,7 @@ def moved_text(self) -> str:
vals = {
c: (
"***" # a secret-named column: its name, never its value
if _SECRET_COLUMN.search(c)
if _secret_column(c)
else f"{text((m.before or {}).get(c))!r} -> {text((m.after or {}).get(c))!r}"
if m.change == "changed"
else text((row or {}).get(c))
Expand Down Expand Up @@ -767,6 +776,11 @@ def _execute() -> Optional[tuple[Rows, Rows]]:
obs = observe(_execute)
if isinstance(obs, Errored):
case.outcome = case.outcome or "ERROR"
if rechecks and case.outcome == Outcome.CONFIRMED.value:
# The write was confirmed but its recheck (or the revert
# before it) crashed: a recheck nobody saw through is
# not a pass, whatever it set before it crashed.
case.recheck = "ERROR"
case.reasons.append(f"{obs.exc_type}: {obs.reason}")
return None
if isinstance(obs, Observed):
Expand Down
Loading