Skip to content

Use JSON Canonicalization Scheme (JCS) - #1488

Open
bact wants to merge 4 commits into
spdx:developfrom
bact:jcs
Open

bact wants to merge 4 commits into
spdx:developfrom
bact:jcs

Conversation

@bact

@bact bact commented Sep 24, 2026 •

Copy link
Copy Markdown
Collaborator

(Replacing #1448)

Adopts JSON Canonicalization Scheme (JCS) (RFC 8785), which is also used by the JSON signature scheme (JSS), for SPDX JSON canonicalization, as proposed in #1362 (from 24 Feb 2026 Tech call discussion) and provided context and details by spdx/spdx-3-model#1065 (comment).

JCS adoption will

JCS aligns and covers most of the SPDX existing canonicalization rules, except for the object key name restriction.
So we can simplify the spec by saying that it uses JCS plus additional object key name restriction (shown below):

  • Object keys:
    A key name shall be a string containing only printable non-space ASCII
    characters in the range U+0021 through U+007E inclusive.

(This is a slight modification from the rules from 3.0, where the range is tighten from U+0021-U+007F, to U+0021-U+007E -- to remove U+007F which is a DEL control character. / It is possible that the inclusion of DEL control character is not intended in the first place, since the range is specifically avoid other control characters (U+0000-U+001F). So this can be considered as a fix, not a breaking change)

The adoption of JCS will allow more convenience for developers, as they can just use existing JCS libraries, which are widely available for different programming languages. With only one additional processing step of object key names.

--

The "Key characteristics of JCS (Informative)" section is optional, provided only for readers' convenience. It can be entirely removed.

To fix #1362 and to fix #1419

- Remove redundant canonicalization rules
- Explicit key ordering by referring to JCS (UTF-16 code units as sort key)

Signed-off-by: Arthit Suriyawongkul <arthit@gmail.com>
@bact bact added this to the 3.1 milestone Sep 24, 2026
@bact bact added the canonicalization Issue for the canonicalization group to discuss label Sep 24, 2026
@bact
bact requested a review from goneall September 24, 2026 09:02
@bact bact modified the milestones: 3.1, 3.1-rc2 Sep 24, 2026
@bact

bact commented Sep 24, 2026

Copy link
Copy Markdown
Collaborator Author

@@henrylyons please kindly review.

Signed-off-by: Arthit Suriyawongkul <arthit@gmail.com>
@goneall
goneall requested a review from zvr September 25, 2026 17:41
@zvr

zvr commented Sep 28, 2026

Copy link
Copy Markdown
Member

I want to check whether this proposed canonical serialization is consistent with the one we already have, or whether we are introducing a breaking change. Does anyone know? I have not yet run tests for a variety of SPDX data.

If it's equivalent, of course we should refer to it, rather than try to define it ourselves.

Comment thread docs/serializations.md
Comment on lines +86 to +88
Any serialization format applied to this specification
shall enforce strict normalization rules for data ordering, formatting,
and encoding to guarantee a consistent output.

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.

No, why? Do you expect "string normalization" for any serialization?

Comment thread docs/serializations.md
shall enforce strict normalization rules for data ordering, formatting,
and encoding to guarantee a consistent output.

For the JSON format, the canonical serialization shall conform to

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.

No, it's not "for the JSON format". It's the canonical serialization of SPDX data.

Comment thread docs/serializations.md
Comment on lines +99 to +120
### Key characteristics of JCS (Informative)

For convenience, the following summarizes essential characteristics inherited
from JCS (RFC 8785) and its underlying I-JSON
([RFC 7493](https://datatracker.ietf.org/doc/rfc7493)) baseline.
Implementations should consult RFC 8785 for exact normative algorithms:

- No extraneous whitespace:
Line breaks, spaces, and tabs do not occur outside of strings.
- Key uniqueness:
Duplicate key names within a single object are strictly prohibited.
- Key ordering:
The name/value pairs within an object are sorted lexicographically based
on the exact UTF-16 code units of the key names.
- Number formatting:
Integers and numeric values are represented in base 10 without leading zeros,
trailing decimal zeros, or unnecessary exponential notation.
- String escaping:
Strings are represented in UTF-8.
Quotation marks (`"`, U+0022), reverse soliduses (`\`, U+005C),
and control characters (U+0000 through U+001F, which includes line breaks
and tabs) are always escaped.

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.

All this has no place in the SPDX spec. We either reproduce the exact rules, or we refer to an external document defining them.

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

canonicalization Issue for the canonicalization group to discuss

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[3.1-RC1] Editorial cleanup: documentation and annexes (7.1) Consider referencing RFC 8785 JSON Canonicalization Scheme (JCS) in canonicalization

3 participants