Skip to content

Harden TQQQ trusted snapshot input boundary - #219

Closed
Pigbibi wants to merge 1 commit into
mainfrom
codex/qsl-p2-tqqq-architecture-first-20260729
Closed

Harden TQQQ trusted snapshot input boundary#219
Pigbibi wants to merge 1 commit into
mainfrom
codex/qsl-p2-tqqq-architecture-first-20260729

Conversation

@Pigbibi

@Pigbibi Pigbibi commented Jul 29, 2026

Copy link
Copy Markdown
Contributor

Scope

  • descriptor-backed, single-open verification for snapshot/evidence inputs
  • strict authentication-before-parse and adversarial regression coverage
  • stable descriptor ownership and fail-closed platform behavior

Validation

  • PYTHONPATH=src python3 -m pytest -q tests/test_tqqq_r1_snapshot.py tests/test_tqqq_trusted_snapshot_package.py
  • PYTHONPATH=src python3 -m pytest -q
  • PYTHONPATH=src python3 -m ruff check (exact four paths)
  • PYTHONPATH=src python3 -m compileall -q src

Immutable review head: 2fa83ffa73d12054c3b41195a9d711527e1fb345

Co-Authored-By: Codex <noreply@openai.com>

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 2fa83ffa73

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +421 to +423
return verify_tqqq_r1_snapshot_fd(directory_fd, expected_manifest_sha256=expected_manifest_sha256)
finally:
os.close(directory_fd)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Preserve the caller's snapshot path in verifier results

On Linux, verify_tqqq_r1_snapshot_fd() records /proc/self/fd/<directory_fd> as SnapshotResult.output_dir, but this wrapper closes that descriptor immediately afterward. Every successful path-based verification therefore returns a missing—or potentially reused—path instead of the caller's directory, breaking the existing result contract and the equality assertion in test_materialize_writes_deterministic_immutable_artifacts.

Useful? React with 👍 / 👎.


manifest = _package_manifest(read_strict_json(package_manifest_payload, "package manifest"))
receipt = _receipt(read_strict_json(receipt_payload, "receipt"))
calendar = _calendar(read_strict_json(calendar_payload, "calendar evidence"))

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Authenticate calendar evidence before parsing it

When the calendar file is tampered with while the externally anchored package manifest and receipt remain valid, this line decodes and validates the unauthenticated calendar before the following digest comparison. A deeply nested payload under the size limit can consequently raise an uncaught RecursionError, and large valid structures consume parsing work even though their hash is already known to be wrong; compare calendar_sha256 with the authenticated manifest and receipt bindings before invoking read_strict_json().

Useful? React with 👍 / 👎.

Comment on lines +204 to +205
except (UnicodeDecodeError, ValueError, json.JSONDecodeError) as exc:
raise TrustedSnapshotPackageError(f"invalid strict JSON: {name}") from exc

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Normalize recursive JSON parser failures

For a sufficiently deeply nested JSON payload, json.loads() raises RecursionError, which is not covered by this exception normalization. Calls to the public read_strict_json()—and package loads whose authenticated evidence is malformed this way—therefore leak an unexpected runtime exception instead of the documented TrustedSnapshotPackageError; include recursive parser failures in the normalized error path.

Useful? React with 👍 / 👎.

Comment on lines +77 to +80
descriptor = self._snapshot_fd
if descriptor >= 0:
try:
os.close(descriptor)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Mark the descriptor closed before releasing it

If two threads call close() concurrently, both can read the same nonnegative descriptor before either call stores -1; after the first os.close() releases it, the operating system may reuse that number and the second call can close an unrelated resource. Atomically claim the descriptor by storing -1 before calling os.close(), or protect this transition with a lock.

Useful? React with 👍 / 👎.

@Pigbibi

Pigbibi commented Jul 29, 2026

Copy link
Copy Markdown
Contributor Author

Fail-closed closure evidence: required CI test run 30452337821 is FAILURE; exact immutable head 2fa83ffa73d12054c3b41195a9d711527e1fb345 has GitHub Codex App review PRR_kwDOR_7pX88AAAABHph39w with unresolved P1/P2 threads PRRT_kwDOR_7pX86UwZjw, PRRT_kwDOR_7pX86UwZj2, PRRT_kwDOR_7pX86UwZj4, and PRRT_kwDOR_7pX86UwZj7. Under the accepted high-risk policy, no patch, re-review, rerun, or merge is authorized. Closing unmerged; local uncommitted correction is retained for audit only.

@Pigbibi Pigbibi closed this Jul 29, 2026
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