Skip to content

fix: refuse an audience credential pair that cannot be compared (#368) - #371

Merged
Polichinel merged 1 commit into
developmentfrom
fix/368-credential-isolation-unprovable
Nov 29, 2026
Merged

Polichinel merged 1 commit into
developmentfrom
fix/368-credential-isolation-unprovable

Conversation

@Polichinel

Copy link
Copy Markdown
Collaborator

Closes #368. Register C-128 (resolved). Fixes a defect released in 1.5.0.

What was wrong

contract/audience.assert_audience_is_not_the_shelf guarded its credential comparison on the operands being non-blank strings:

if (isinstance(audience_credential, str) and isinstance(shelf_credential, str)
        and audience_credential.strip()
        and audience_credential.strip() == shelf_credential.strip()):

A blank, absent or non-string credential therefore skipped the comparison and fell through to the success path, which logs "audience connection is isolated from the shared shelf (distinct projects and distinct credentials, values not logged)". It had compared no credentials.

The same function already refuses exactly this shape for the shelf project id, naming the polarity C-113 was closed to fix — a gate whose input is missing must report a refusal or a skip, never a pass. The credential half of the same connection did the opposite.

Why it was reachable

appwrite_env.assert_env_declared decides membership with not os.getenv(name), so it refuses an absent or empty key — but a single space is truthy. APPWRITE_CRAFD_PUBLISHER_API_KEY=" " passed the declaration check and reached this function, which was the last place that shape could have been caught. The run would have failed as a 401 from inside the delivery, after the contract resolution, every manifest download and the 888 KB GAUL lookup.

Second half, same seam

The function returned only the stripped project id and the manager then re-read the credential with a raw os.getenv. The docstring argues at length why returning the checked project id matters; that argument was made for one half of the connection and left open for the other. A key acquired with $(cat ...) passed isolation and sent a trailing newline in the authorization header.

What changed

  • Both credentials are refused when absent, blank or not a string, with the same CANNOT BE PROVEN wording and no value printed (C-89 — this repository is public and its CI logs are world-readable).
  • The function returns a frozen AudienceConnection carrying both stripped halves. Named fields rather than a two-tuple: two same-typed strings unpacked positionally transpose in silence, which is the mirror image of the hazard that made the arguments keyword-only.
  • crafd/managers/crafd.py passes on both checked halves instead of re-reading either.

Proof — eight mutations, all caught

Applied to the real files and reverted; the suite run between each.

mutation verdict
audience-credential presence branch deleted CAUGHT (5 failed)
shelf-credential presence branch deleted CAUGHT (4 failed)
the shipped 1.5.0 shape restored verbatim CAUGHT (5 failed)
credential returned unstripped CAUGHT (2 failed)
equality check weakened to identity CAUGHT (4 failed)
project and credential transposed in the returned pair CAUGHT (6 failed)
manager re-reads the key from the environment CAUGHT (1 failed)
success line logged before the credential checks CAUGHT (8 failed) — see below

The last row is the finding, and it was in my own tests

Mutation M8 initially SURVIVED the entire file, including all four assert "isolated from the shared shelf" not in caplog.text assertions — the ones written to prove this very defect fixed. The success line is logged at INFO; the root logger sits at WARNING; so caplog.text was empty and the negative assertion was true of any code whatsoever. One of the four was pre-existing, written with C-113's own fix.

All four now set caplog.at_level(logging.INFO), and test_the_success_line_is_captured_when_the_level_is_set asserts the line is seen on the happy path — an anchor that fails if the line is renamed, demoted or removed, which is exactly when the negative assertions would quietly stop meaning anything. That is cluster O inside the fix for a cluster-O defect, and it is recorded as such in C-128.

Tests

tests/test_audience_isolation.py, 22 → 40 tests. The seven input pairs measured while filing #368 are kept in the order they were measured, so the table in the issue and the table in the suite are the same table. Two manager-level tests assert on the AppwriteConfig actually built, per the #356 lesson that nine tests of the rule all passed with the rule deleted from the manager.

Tracking

  • The audience-isolation check reports 'distinct credentials' having compared nothing #368 — closed by this PR.
  • Register C-128 — filed resolved, with the measurement table and the M8 finding; cluster O's second discharge, cross-referenced to C-126, C-113, C-89, C-81, C-125 and vpp_018 §4.
  • ADR-018 §4 amended — it named two things to refuse and left out the third. An uncomparable pair is now stated as a refusal, with why it is a different reason from the other two.
  • CHANGELOG.md — an Unreleased section, written for the consumer: a run with a blank key now stops at the start instead of in the middle.

Not done here, deliberately

Verification

Suite on the supported interpreter (views-models/envs/views-postprocessing/bin/python, 3.11.15): 654 passed, 3 skipped, 41 xfailed, and the one pre-existing failure — the poetry.lock drift tracked as views-models#757. Ruff clean across the repository. Manager line count 473 against the 475 budget.

🤖 Generated with Claude Code

https://claude.ai/code/session_01ANY1CCy9Xo7zjMY4XJ69v9

`assert_audience_is_not_the_shelf` guarded its credential comparison on the
operands being non-blank strings, so a blank, absent or non-string credential
skipped the comparison and fell through to the success path — which logs that
the two connections used "distinct projects and distinct credentials". It had
compared no credentials. Shipped in 1.5.0; measured on seven input pairs.

The same function already refuses exactly this shape for the shelf project id,
naming the polarity C-113 was closed to fix: a gate whose input is missing
reports a refusal or a skip, never a pass. The credential half did the opposite.

Reachable in practice because `assert_env_declared` decides membership with
`not os.getenv(name)` and a single space is truthy, so
`APPWRITE_CRAFD_PUBLISHER_API_KEY=" "` passed the declaration check and this
was the last place that shape could have been caught. The run would have failed
as a 401 from inside the delivery, after the contract resolution, every manifest
download and the 888 KB GAUL lookup.

Also closes the strip asymmetry at the same seam: the function returned only the
stripped project id and the manager re-read the key with a raw `os.getenv`, so
the docstring's "return what was compared" argument covered one half of the
connection and left the other open. It now returns a frozen `AudienceConnection`
carrying both stripped halves, with named fields rather than a two-tuple —
two same-typed strings unpacked positionally transpose in silence, the mirror
image of the hazard that made the arguments keyword-only.

Eight mutations applied to the real files and reverted, all eight caught,
including the shipped 1.5.0 shape restored verbatim.

Mutation M8 — log the success line before the credential checks — initially
SURVIVED the whole file, including the four `assert "isolated from the shared
shelf" not in caplog.text` assertions written to prove this defect fixed. The
line is logged at INFO, the root logger sits at WARNING, so `caplog.text` was
empty and the assertion was true of any code at all. One of the four was
pre-existing, written with C-113's own fix. All four now set
`caplog.at_level(logging.INFO)`, and a new test asserts the line IS captured on
the happy path so the negative assertions have an anchor.

Nothing delivers through this path yet (`UPLOAD_ENABLED` is False, C-126), so no
run changes behaviour today. Fixed on development rather than as a 1.5.1: no one
is exposed, and a patch release nothing installs costs more attention than it buys.

Tracked: issue #368, register C-128 (resolved, cluster O's second discharge),
ADR-018 §4 amended to state that an uncomparable pair is a refusal, and an
Unreleased section in CHANGELOG.md.

Suite on the supported interpreter (3.11.15): 654 passed, 3 skipped, 41 xfailed,
1 pre-existing failure (the poetry.lock drift, views-models#757). Ruff clean.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01ANY1CCy9Xo7zjMY4XJ69v9
@Polichinel
Polichinel merged commit 025cfa2 into development Nov 29, 2026
4 checks passed
@Polichinel
Polichinel deleted the fix/368-credential-isolation-unprovable branch November 29, 2026 01:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant