Skip to content

Harden TQQQ trusted snapshot boundary - #218

Closed
Pigbibi wants to merge 2 commits into
mainfrom
codex/qsl-p2-trust-boundary-v3-20260729
Closed

Harden TQQQ trusted snapshot boundary#218
Pigbibi wants to merge 2 commits into
mainfrom
codex/qsl-p2-trust-boundary-v3-20260729

Conversation

@Pigbibi

@Pigbibi Pigbibi commented Jul 29, 2026

Copy link
Copy Markdown
Contributor

Summary

  • bind trusted snapshot reads to an opened directory descriptor and fail closed when stable descriptor capabilities are unavailable
  • authenticate package/receipt/calendar bytes before decoding and normalize oversized-integer parse failures
  • add regression coverage for directory replacement, pre-authentication decode ordering, and oversized integers

Scope

  • src/us_equity_snapshot_pipelines/tqqq_trusted_snapshot_package.py
  • src/us_equity_snapshot_pipelines/tqqq_r1_snapshot.py
  • tests/test_tqqq_trusted_snapshot_package.py

No schema, dependency, workflow, ruleset, provider, data, or live changes.

Verification

  • PYTHONPATH=src python3 -m pytest -q (exit 0)
  • focused package/snapshot tests: 40 passed
  • python3 -m compileall -q src tests
  • git diff --check
  • Ruff unavailable in local environment

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: fcf5dca7b3

ℹ️ 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 thread src/us_equity_snapshot_pipelines/tqqq_trusted_snapshot_package.py Outdated
Comment thread src/us_equity_snapshot_pipelines/tqqq_r1_snapshot.py Outdated
Comment thread src/us_equity_snapshot_pipelines/tqqq_trusted_snapshot_package.py Outdated
Comment thread src/us_equity_snapshot_pipelines/tqqq_r1_snapshot.py Outdated
Co-Authored-By: Codex <noreply@openai.com>
@Pigbibi

Pigbibi commented Jul 29, 2026

Copy link
Copy Markdown
Contributor Author

@codex review

@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: e5ad796363

ℹ️ 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".


import ctypes
import errno
import fcntl

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 Guard the Unix-only fcntl import

On Windows, where the standard-library fcntl module is unavailable, importing tqqq_r1_snapshot now fails immediately with ModuleNotFoundError. This bypasses the intended fail-closed platform checks and also makes the otherwise portable path-based verifier unavailable; guard the import as the new trusted-package module does.

Useful? React with 👍 / 👎.

Comment on lines +158 to +161
if source.is_symlink() or not source.is_file():
_invalid(f"{name} must be a regular non-symlink file")
try:
return source.read_bytes()

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 Open evidence files before checking their type

When an evidence file's parent directory is concurrently writable, the separate is_symlink()/is_file() checks can inspect one inode and read_bytes() can open another. An attacker repeatedly replacing the path with a FIFO or device can therefore block the loader or cause unbounded reads before any hash check occurs; open each file once with O_NOFOLLOW | O_NONBLOCK, validate that descriptor with fstat, and read from the same descriptor.

Useful? React with 👍 / 👎.

Comment on lines +70 to +76
fd = self._snapshot_fd
if fd >= 0:
try:
os.close(fd)
except OSError:
pass
object.__setattr__(self, "_snapshot_fd", -1)

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 Keep the package hash stable after close

Because this frozen dataclass receives an autogenerated hash that includes _snapshot_fd, mutating that field in close() changes both its hash and equality state. If a package is used as a dictionary key or set member and then explicitly or contextually closed, subsequent lookup or removal can fail; exclude lifecycle fields from comparison and hashing or make the class unhashable.

Useful? React with 👍 / 👎.

Comment on lines +34 to +35
@dataclass(frozen=True, init=False)
class TrustedSnapshotPackage:

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 Prevent copies from sharing ownership of the descriptor

The dataclass can be shallow-copied even though each instance treats _snapshot_fd as exclusively owned. copy.copy(package) therefore creates two objects holding the same descriptor; closing one leaves the other apparently open, and after that descriptor number is reused, closing or finalizing the copy can close an unrelated resource. Reject copying/serialization or duplicate the descriptor while defining clear ownership.

Useful? React with 👍 / 👎.

receipt_sha256: str
calendar_sha256: str
_snapshot_fd: int
_snapshot_members: tuple[tuple[str, bytes], ...]

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 Exclude verified snapshot bytes from the generated repr

The autogenerated dataclass repr includes _snapshot_members, so logging or interpolating a trusted package emits every byte of prices.csv and the metadata files. For real multi-year snapshots this can produce very large logs and unnecessarily expose the complete dataset; declare this internal field with repr=False, as is already done for SnapshotResult.verified_members.

Useful? React with 👍 / 👎.

@Pigbibi

Pigbibi commented Jul 29, 2026

Copy link
Copy Markdown
Contributor Author

Fail-closed settlement: required CI succeeded at exact head e5ad79636331a67fa58b3d488d23bcb05de8c437, but the final current-head GitHub Codex review added five unresolved P2 findings. The authorized lifecycle (initial review -> one consolidated remediation -> final review) is exhausted. No third patch/review, thread mutation, rerun, or merge will be performed; closing unmerged and preserving evidence for the Pre-P3 architecture review.

@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