Skip to content

fix(sdk): DSPX-1561 parse manifests strictly - #4305

Open
dmihalcik-virtru wants to merge 1 commit into
mainfrom
DSPX-1561-strict-manifest
Open

dmihalcik-virtru wants to merge 1 commit into
mainfrom
DSPX-1561-strict-manifest

Conversation

@dmihalcik-virtru

@dmihalcik-virtru dmihalcik-virtru commented Nov 9, 2026 •

Copy link
Copy Markdown
Member

Proposed Changes

  • Manifests are checked under the ZTDF assertions specification, Section 3, in LoadTDF, IsValidTdf, and Manifest.UnmarshalJSON, whether or not assertion verification is enabled. A scanner reads the raw bytes first, because encoding/json keeps the last duplicate member, matches names case-insensitively, and replaces invalid Unicode. Rejected:
    • duplicate member names anywhere, including escaped spellings (duplicate-member);
    • at every level of the manifest the SDK models, a case variant of a modelled member name, or two members whose names differ only in case (ambiguous-member). The IsStreamable spelling written by older Java SDKs under encryptionInformation.method is still accepted;
    • invalid UTF-8 anywhere, and lone surrogates, noncharacters, and out-of-range numbers inside assertion objects (invalid-json).
  • Text that is not JSON at all keeps its existing error. LoadTDF remains parse-only.
  • ErrAssertionFailure gains Reason (AssertionFailureReason constants with the Section 9 codes). It still unwraps to ErrTampered; its message carries reason=<code>, and the id is escaped and length-capped. When there is no id, the message no longer ends in an empty id: .

Split out of #4301 (draft; the complete change). Cross-SDK counterparts: opentdf/java-sdk#436, opentdf/web-sdk#1139.

Compatibility: manifests with duplicate or case-variant member names, or invalid UTF-8, no longer load. A scan of legitimate manifests found none affected apart from the accepted IsStreamable spelling.

Checklist

  • I have added or updated unit tests
  • I have added or updated integration tests (if appropriate)
  • I have added or updated documentation

Testing Instructions

  • cd sdk && go test ./... -race (sdk/assertion_parse_test.go, sdk/assertion_json_test.go, sdk/null_statement_test.go); cd otdfctl && go test ./... (pkg/handlers/tdf_errors_test.go checks the typed failure reaches the CLI).

Apply the parsing rules of the ZTDF assertions specification, Section 3,
before LoadTDF or IsValidTdf decodes a manifest, and in
Manifest.UnmarshalJSON, whether or not assertion verification is enabled.
encoding/json keeps the last of duplicate members, folds case when matching
names, and replaces invalid Unicode, so a scanner reads the raw bytes
first:

- duplicate member names anywhere in the manifest, compared after decoding
  escapes, fail with duplicate-member;
- at every level of the manifest the SDK models, a case variant of a
  modelled member name, or two members whose names are case variants of
  each other, fail with ambiguous-member. The IsStreamable spelling that
  older Java writers used under encryptionInformation.method is still
  accepted;
- invalid UTF-8 anywhere, and lone surrogates, noncharacters, and
  out-of-range numbers inside an assertion object, fail with invalid-json.

Text that is not JSON at all, such as a manifest starting with a byte
order mark, keeps its existing error. LoadTDF still only parses.

ErrAssertionFailure gains a Reason holding a Section 9 code. It still
unwraps to ErrTampered, and its message carries reason=<code>, with the id
escaped and length-capped since it comes from the file.

Signed-off-by: Dave Mihalcik <dmihalcik@virtru.com>
@dmihalcik-virtru
dmihalcik-virtru requested review from a team as code owners November 9, 2026 14:50
@coderabbitai

coderabbitai Bot commented Nov 9, 2026

Copy link
Copy Markdown

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 59 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: ASSERTIVE
  • Plan: Advanced
  • Run ID: 39de7170-a227-49fb-98f3-8dba46adbf1c
Commits

Reviewing files that changed from the base of the PR and between 57f15c4 and 9531e39.

Files selected for processing: 9

  • otdfctl/pkg/handlers/tdf_errors_test.go
  • sdk/assertion_json.go
  • sdk/assertion_json_test.go
  • sdk/assertion_parse_test.go
  • sdk/manifest.go
  • sdk/null_statement_test.go
  • sdk/sdk.go
  • sdk/tdf.go
  • sdk/tdferrors.go
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@github-actions

github-actions Bot commented Nov 9, 2026

Copy link
Copy Markdown
Contributor
Benchmark results, click to expand

Bulk Benchmark Results

Metric Value
Total Decrypts 100
Successful Decrypts 100
Failed Decrypts 0
Total Time 346.604889ms
Throughput 288.51 requests/second

TDF3 Benchmark Results

Metric Value
Total Requests 5000
Successful Requests 5000
Failed Requests 0
Concurrent Requests 50
Total Time 36.180157312s
Average Latency 360.940161ms
Throughput 138.20 requests/second

@github-actions

github-actions Bot commented Nov 9, 2026

Copy link
Copy Markdown
Contributor

⚠️ Govulncheck found vulnerabilities ⚠️

The following modules have known vulnerabilities:

  • otdfctl
  • sdk
  • service
  • tests-bdd

See the workflow run for details.

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

comp:sdk A software development kit, including library, for client applications and inter-service communicati size/l

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants