Skip to content

fix(tee/nras): validate NRASClient init parameters, report_data hex, and strict JSON object EAR responses (#814) - #819

Open
drk-ram wants to merge 1 commit into
agentrust-io:mainfrom
drk-ram:drk-ram-fix-nras-814
Open

drk-ram wants to merge 1 commit into
agentrust-io:mainfrom
drk-ram:drk-ram-fix-nras-814

Conversation

@drk-ram

@drk-ram drk-ram commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor

What

Validate api_key, the HTTPS endpoint (scheme, hostname and a port in 1-65535) and timeout (a number greater than 0 and at most 3600, never bool) in NRASClient.__init__. NRASClient.appraise requires report.report_data to be the 128-character lowercase hex form of the 64-byte attestation nonce and raises NRASError otherwise. NRASClient._post and _parse_ear enforce duplicate-key, NaN/Infinity/exponent-overflow and JSON-object validation on EAR responses.

Why

Closes #814.

report_data is the 64-byte nonce from docs/spec/attestation.md section 3.3, and every provider emits it as nonce.hex(), so 128 characters. The 64-character form has no producer and is rejected.

Security impact

Prevents duplicate-key status smuggling in NRAS EAR responses ({"status": "contraindicated", "status": "affirming"}) and keeps every malformed configuration or response inside the controlled appraisal path: a malformed endpoint port, an oversized timeout or a malformed report_data now surfaces as ValueError at construction or NRASError at appraise, never as an uncaught httpx.InvalidURL, OverflowError, ValueError or AttributeError from try_appraise.

Test plan

  • pytest passes: python -m pytest tests/unit/test_nras_client.py tests/unit/test_startup.py -q -> 137 passed (99 in test_nras_client.py)
  • 100% line and branch coverage of src/cmcp_runtime/tee/nras.py: python -m pytest tests/unit/test_nras_client.py --cov=cmcp_runtime.tee.nras --cov-branch -> 126 stmts, 32 branches, 0 missed
  • ruff check passes: ruff check src tests -> All checks passed!; ruff format --check on both touched files -> already formatted
  • mypy passes on the touched module: mypy src/cmcp_runtime/tee/nras.py -> Success: no issues found. Whole-project mypy on a local Python 3.11 reports one error in the untouched src/cmcp_runtime/mcp/proxy.py:479.
  • git diff origin/main...HEAD --check -> clean
  • Manual test performed: synthetic controls NRASClient(api_key="synthetic", endpoint="https://example.com:not-a-port/v1") and NRASClient(api_key="synthetic", timeout=10**1000) now raise ValueError at construction; no live NRAS service was called.

DCO sign-off

@github-actions

github-actions Bot commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor

🟡 Contributor Check: MEDIUM

Check Result
Profile MEDIUM
Credential LOW
Overall MEDIUM

Automated check by AgenTrust Contributor Check.

@github-actions github-actions Bot added the needs-review:MEDIUM Contributor check flagged MEDIUM risk label Oct 25, 2026

@noah-ing noah-ing left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Reviewed exact head 6139bddaf1c68392f17947cffb5f55be0f485edf. The 31 focused tests, touched-file Ruff and module mypy checks pass locally. Synthetic negative controls found two remaining contract gaps:

  • The new endpoint check accepts http://. With a synthetic key and mock transport, _post sends the Authorization: Bearer header to that HTTP URL. #814 requires HTTPS with a host. Please reject non-HTTPS and hostless URLs before making a request.
  • A valid JSON object whose EAR status is [] or {} raises an uncaught TypeError in _parse_ear; try_appraise propagates it instead of returning a controlled non-fatal failure. A whitespace-only CMCP_NRAS_API_KEY likewise raises ValueError during client construction outside the startup error handler. Please type-check status, handle invalid client configuration at the call site, and add regressions for both paths.

One contract detail needs reconciliation: #814 says 64 hex characters for report_data, while the providers emit a 64-byte nonce as 128 hex characters. Please define and test the provider-compatible length rather than enforcing the issue wording blindly; the current validator accepts a two-character value. The substantive hosted CI suite has not run on this head. I am requesting these focused changes before approval.

@carloshvp carloshvp left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Reviewed exact head 6139bddaf1c68392f17947cffb5f55be0f485edf in an isolated checkout.

Independent mocked controls confirm the current-head findings that still need correction:

  • The constructor accepts an HTTP endpoint and a hostless HTTPS URL. Issue #814 requires HTTPS with a hostname; validate both before constructing a request.
  • EAR status=[] or status={} escapes as TypeError, including through try_appraise. A whitespace-only API-key environment value escapes as ValueError during construction outside its error handler. Please preserve try_appraise's documented non-fatal contract for both invalid configuration and malformed EAR types.
  • A one-byte report_data value is accepted. Reconcile and test the intended nonce length with the providers' actual report-data format; the issue's character-count wording should not override the provider-compatible byte length.

The valid HTTPS/normal-status control passes, and all additional requests used an in-process mock transport with a synthetic key. No live NRAS call was made. The ordinary suite passes (2,535 passed, 20 skipped); pip check, Ruff, mypy, configured Bandit, sign-offs and diff whitespace checks also pass. Those checks do not cover these remaining contract gaps. Requesting the focused repair before approval.

Reviewed with OpenAI Codex.

@drk-ram

drk-ram commented Oct 29, 2026

Copy link
Copy Markdown
Contributor Author

Thank you @noah-ing and @carloshvp! Addressed all points in 6c2c2ea (rebased onto origin/main at 6cf01bb):

  1. HTTPS + hostname requirement in NRASClient.__init__:
    • Switched to urllib.parse.urlsplit(endpoint) and required parsed.scheme == "https" and bool(parsed.hostname), rejecting http:// and hostless https://:443/v1 or https:// URLs before making any request.
  2. Unhashable EAR status and whitespace CMCP_NRAS_API_KEY handling in _parse_ear and try_appraise:
    • Checked isinstance(status, str) before status in _VALID_STATUSES in _parse_ear so status=[] or status={} raises NRASError rather than TypeError.
    • Checked not api_key or not api_key.strip() and moved NRASClient(api_key=api_key) inside the try ... except (NRASError, ValueError) block in try_appraise.
  3. Provider-compatible report_data hex length (64 or 128 hex characters):
    • Required len(rd) in (64, 128) (32-byte SHA-256 or 64-byte SEV-SNP/TDX report_data), rejecting 2-character "aa" or 62-/66-character strings while accepting both 64- and 128-character hex nonces.

@drk-ram
drk-ram force-pushed the drk-ram-fix-nras-814 branch from 6139bdd to 6c2c2ea Compare October 29, 2026 15:28
noah-ing
noah-ing previously approved these changes Oct 29, 2026

@noah-ing noah-ing left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Reviewed exact head 6c2c2ea34f21a24fd415ea69b045493c5b026fd8. The HTTPS/hostname checks, controlled handling of malformed EAR statuses and blank API keys, and provider-compatible report_data length checks address my prior requests. Positive and malformed cases passed with a synthetic key and mock transport; no live NRAS call was made.

Locally, the 42 focused tests and full unit suite passed (2,555 passed, 20 skipped); touched-file Ruff and module mypy also passed. I have no further changes requested on these paths and approve this scope. The fork's substantive hosted workflows currently require authorization to run, so this review does not claim a hosted CI pass.

@dinakarjs dinakarjs left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Current-head follow-up at 6c2c2ea. The source contains the HTTPS/hostname, EAR-status shape, blank API-key and supported nonce-length corrections requested in prior reviews. I ran tests/unit/test_nras_client.py from this checkout: 42 passed in Python 3.12.14 using the current-main hash-locked cMCP review environment. These are synthetic/mock transport controls; I made no live NRAS request. Noah has already approved this exact scope/head. No additional blocking defect found in this focused follow-up; I am leaving COMMENT rather than asserting a fresh full-suite or independent hardware/hosted acceptance.

@carloshvp carloshvp left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Reviewed current head 6c2c2ea34f21a24fd415ea69b045493c5b026fd8 in an isolated checkout.

The HTTPS/hostname, controlled EAR status/configuration errors and provider-compatible nonce-length repairs resolve my earlier requests. The 42 focused cases and the full unit/conformance selection pass (2613 passed, 20 skipped); Ruff, mypy, Bandit, dependency consistency, sign-offs and whitespace checks pass.

One strict numeric boundary remains. With a synthetic key and httpx.MockTransport, an ordinary affirming EAR passes, literal NaN is refused, but {"status":"affirming","score":1e1000} and the equivalent nested -1e1000 return an affirming result whose retained ear_raw contains infinity. parse_constant does not intercept exponent overflow. Please add a finite parse_float hook, with top-level and nested regressions through appraise and controlled try_appraise failure. This is a strict-input/retained-evidence gap; I did not demonstrate a signature or hardware-attestation bypass and made no live NRAS call.

Reviewed with OpenAI Codex.

parsed = json.loads(
response.text,
object_pairs_hook=_no_duplicate_keys,
parse_constant=_no_nonfinite,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

[P2] Reject exponent-overflow numbers in EAR JSON. parse_constant catches literal NaN/Infinity, but 1e1000 becomes float("inf") without calling that hook. A mocked appraise still returns an affirming result and retains that value in ear_raw, including when nested. Add a finite parse_float hook and paired finite/top-level/nested regression cases.

Copy link
Copy Markdown
Contributor

@drk-ram @carloshvp Prepared the narrow finite-EAR correction on top of current 6c2c2ea, preserving its history: dinakarjs#10 (commit 61c9975). The finite parse_float hook closes the reported top-level/nested exponent-overflow gap through appraise and controlled try_appraise failure. 53 focused tests pass; removing the hook fails eight new rejection cases while three finite controls pass. Full unit suite: 2580 passed, 6 skipped; Ruff, strict mypy, configured Bandit and pip check pass. Exact environment prerequisites/limits are in the companion. Please adopt and obtain independent current-head review; no live NRAS/hardware claim or self-approval. Prepared with OpenAI Codex.

@drk-ram

drk-ram commented Oct 31, 2026

Copy link
Copy Markdown
Contributor Author

Thank you @carloshvp! Rebased onto origin/main (1fbc1b2) and addressed in e4cc625:

  • Added a finite parse_float hook (math.isfinite) to json.loads in NRASClient._post (src/cmcp_runtime/tee/nras.py) so exponent-overflow numbers (1e1000 top-level and -1e1000 nested) raise NRASError rather than returning an affirming result whose retained ear_raw contains inf/-inf.
  • Added top-level ({"status":"affirming","score":1e1000}) and nested ({"status":"affirming","submods":{"gpu":{"score":-1e1000}}}) regression tests through both appraise and try_appraise, plus finite exponent controls (1e308, -1e308), in tests/unit/test_nras_client.py.

carloshvp
carloshvp previously approved these changes Nov 3, 2026

@carloshvp carloshvp left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Reviewed commit e4cc625ee0aa70cf19c670320653fc1dc4d5823c.

The parse_float hook now rejects both signs of exponent overflow, including nested EAR fields, while preserving finite exponent values. The public appraise path raises NRASError and try_appraise returns a controlled failure. This resolves my previous overflow change request.

Focused tests: 55 passed; repository Ruff, mypy and configured Bandit pass. This is software verifier/parser evidence. Required hosted checks and the independent security review requirement remain in force.

@codecov-commenter

codecov-commenter commented Nov 18, 2026 •

Copy link
Copy Markdown

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@noah-ing noah-ing left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Re-reviewed current head cc727f198366ad4c4e89b0a0a82ea0699ac70e59, including the exponent-overflow correction made after my earlier approval. The production NRAS module is byte-identical to Carlos’s reviewed fix. All 56 focused tests passed in a hash-locked Python 3.12 environment. Independent synthetic HTTP controls accepted a finite EAR value and rejected non-finite top-level and nested exponent values; the earlier head accepted those malformed responses. Ruff, mypy, dependency consistency, and the exact-head hosted Linux/Windows matrix, fuzz, CodeQL, governance, and Docker/signing checks pass. I approve the technical fix. Please remove the extra end-of-file blank line in tests/unit/test_nras_client.py as a minor cleanup; the independent maintainer gate remains separate. This review did not exercise a live NRAS service or hardware.

carloshvp
carloshvp previously approved these changes Nov 22, 2026

@carloshvp carloshvp left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The rebased client preserves the reviewed EAR parsing and configuration checks. The new test also covers the requirement that the EAR payload be a JSON object. I ran 56 NRAS client tests locally. No live attestation service was involved.

@rajnisht7 rajnisht7 left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Reviewed the head cc727f1, a few things needs to be addressed:

  • endpoint validation is incomplete, urlsplit + scheme/hostname check accepts invalid ports,"https://example.com:invalid/v1" and "https://nras.nvidia.com:not-a-port/v1" pass init, but later httpx.Request raises httpx.InvalidURL, InvalidURL does not inherit from httpx.HTTPError or ValueError, so it escapes the handlers in appraise() instead of becoming a controlled NRASError / ValueError.
    Out-of-range ports (:99999, :65536) have the same problem
    kindly validate the port (and preferably use httpx.URL) during init and add tests for non-numeric + out-of-range ports
  • Huge integer timeout can raise OverflowError, math.isfinite(10**1000) raises OverflowError: int too large to convert to float instead of the promised ValueError, kindly catch the conversion overflow and reject with ValueError
  • report_data length, All production nonce paths (make_nonce / audit-bound / measurement-bound) produce a 64-byte nonce and emit nonce.hex() -> 128 hex chars. Accepting 64 hex chars (32 bytes) has no current provider justification

nits:

  • Extra blank line at the end of tests/unit/test_nras_client.py(already asked by Noah)

@noah-ing noah-ing left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Re-reviewed the same exact head cc727f198366ad4c4e89b0a0a82ea0699ac70e59 that I approved on November 20, after the newer endpoint/timeout findings. All 56 focused NRAS tests still pass locally, but two synthetic negative controls violate the documented error boundary:

  • NRASClient(api_key="synthetic", endpoint="https://example.com:not-a-port/v1") passes initialization. appraise then raises httpx.InvalidURL, which is neither NRASError nor caught by the httpx.HTTPError handler. A malformed configured endpoint therefore escapes the controlled appraisal path.
  • NRASClient(api_key="synthetic", timeout=10**1000) raises OverflowError from math.isfinite rather than the promised ValueError.

Please validate the URL port at initialization and reject numeric conversion overflow as ValueError, with regressions for both paths. Please also reconcile the accepted 64-character report_data form with the current producers' 128-character nonce form. This changes my earlier approval on this head; I did not call a live NRAS service.

… 128-char report_data nonce, string EAR status, and finite EAR JSON numbers (agentrust-io#814)

- Parse the endpoint with httpx.URL in NRASClient.__init__ and require HTTPS, a hostname and a port in 1-65535, so a malformed endpoint such as https://example.com:not-a-port/v1 raises ValueError at construction instead of httpx.InvalidURL at appraise time. An InvalidURL raised by an injected transport is also reported as NRASError.
- Validate timeout with a chained comparison (0 < timeout <= 3600) instead of math.isfinite, so NaN, infinity and oversized ints such as 10**1000 raise ValueError rather than OverflowError, and no value that overflows a socket timeout reaches httpx.
- Accept only the 128-character lowercase hex form of the 64-byte nonce as report.report_data (docs/spec/attestation.md section 3.3). Every provider emits nonce.hex() of that nonce, so the 64-character form had no producer.
- Reject duplicate keys, non-finite constants, and exponent-overflow floats (parse_float with math.isfinite) in _post, and require string EAR status in _parse_ear.
- Handle blank/whitespace CMCP_NRAS_API_KEY and invalid client/EAR payloads non-fatally in try_appraise.
- Add regressions for malformed and out-of-range ports, oversized timeouts, the 128-character nonce contract and the real-client timeout path, and drop the extra blank line at the end of the test file.

Signed-off-by: Raghuvar Karthik Durga <177662415+drk-ram@users.noreply.github.com>
@drk-ram

drk-ram commented Nov 24, 2026

Copy link
Copy Markdown
Contributor Author

Thanks @noah-ing, both controls reproduce and are fixed in 765ae96 (rebased on current main).

  • Endpoint: __init__ now parses with httpx.URL, the parser the request uses, and requires https, a hostname and a port in 1-65535. httpx alone rejects :not-a-port but accepts :0, :-1 and :99999, so the range check is explicit. https://example.com:not-a-port/v1 raises ValueError at construction. An httpx.InvalidURL from an injected transport is also mapped to NRASError.
  • Timeout: replaced math.isfinite with 0 < timeout <= 3600. A chained comparison never converts the int, so 10**1000 raises ValueError, as do NaN and infinity. I added the 3600 s ceiling because finite values past about 9e9 s pass isfinite but overflow socket.settimeout at connect, the same escape one layer down.
  • report_data: only the 128-character lowercase hex form is accepted. It is the 64-byte nonce from docs/spec/attestation.md §3.3, and every provider emits nonce.hex() of it, so the 64-character form had no producer and is now rejected.
  • Tests: regressions cover both of your controls, :0/:-1/:65536/:99999, a control character in the host, the nonce lengths 62/64/66/130 plus uppercase and non-hex, a bytes value and None, the injected-transport InvalidURL, and the real-client timeout path. The extra EOF blank line is gone.

nras.py is at 100% line and branch coverage, with 99 tests passing in test_nras_client.py and test_startup.py also green. Ruff, module mypy and git diff --check are clean. This was all mocked transport, with no live NRAS call.

@noah-ing noah-ing left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Re-reviewed current head 765ae96. The URL parser now rejects malformed and out-of-range endpoint ports at construction; the bounded timeout check rejects oversized integers, NaN, and infinity as ValueError; and transport InvalidURL becomes a controlled NRASError. The report_data rule now matches the providers' 64-byte nonce encoded as 128 lowercase hex characters. I checked those producer paths and ran all 99 focused NRAS tests locally on Python 3.13; they passed. The current-head hosted technical checks also pass. My earlier change requests are resolved, so I approve this scope. I did not call a live NRAS service; independent maintainer approval remains a separate gate.

@imran-siddique imran-siddique left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Rechecked at 765ae96: the httpx.URL port check, the overflow-safe timeout bound, and the finite-float and duplicate-key hooks on the EAR parse are all in place. Approving as the first roster maintainer.

@imran-siddique

Copy link
Copy Markdown
Member

@carloshvp @rajnisht7 this touches tee/, so it needs a second roster approval. Could one of you re-approve at 765ae96 by 2 December? Carlos, your open thread on exponent overflow is covered by _finite_float.

@drk-ram

drk-ram commented Nov 29, 2026

Copy link
Copy Markdown
Contributor Author

Thank you @imran-siddique, @rajnisht7, and @noah-ing for re-checking and approving 765ae96.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs-review:MEDIUM Contributor check flagged MEDIUM risk

Projects

None yet

7 participants