Repository navigation
fix: refuse an audience credential pair that cannot be compared (#368) - #371
Merged
Merged
Conversation
`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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #368. Register C-128 (resolved). Fixes a defect released in 1.5.0.
What was wrong
contract/audience.assert_audience_is_not_the_shelfguarded its credential comparison on the operands being non-blank strings: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_declareddecides membership withnot 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
CANNOT BE PROVENwording and no value printed (C-89 — this repository is public and its CI logs are world-readable).AudienceConnectioncarrying 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.pypasses 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.
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.textassertions — the ones written to prove this very defect fixed. The success line is logged at INFO; the root logger sits at WARNING; socaplog.textwas 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), andtest_the_success_line_is_captured_when_the_level_is_setasserts 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 theAppwriteConfigactually built, per the #356 lesson that nine tests of the rule all passed with the rule deleted from the manager.Tracking
Unreleasedsection, written for the consumer: a run with a blank key now stops at the start instead of in the middle.Not done here, deliberately
UPLOAD_ENABLEDisFalse, C-126) and the CRAF'd publisher key still has no carrier (views-models#755), so no one is exposed and a patch release nothing installs costs more attention than it buys. The operator's call, taken.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 — thepoetry.lockdrift 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