Harden constitution validation for JWT, CA, and member keys#7924
Merged
Conversation
Copilot
AI
changed the title
[WIP] Fix insufficient strictness in constitution validators
Harden constitution validation for JWT, CA, and member keys
Jun 5, 2026
achamayou
reviewed
Jun 5, 2026
achamayou
reviewed
Jun 5, 2026
Member
|
@copilot add a relevant changelog entry |
Contributor
Author
- Use ceiling division when sizing EC coordinate/private-scalar buffers so curves whose bit-size is not a multiple of 8 (P-521 has 521 bits) get the full 66-byte buffer rather than a truncated 65-byte one. This fixes BN_bn2binpad failures and dropped leading-zero bytes when round-tripping P-521 keys through JWK. - Update test_jwt_auth_raw_key to use an https:// JWT issuer URL so it satisfies the hardened set_jwt_issuer constitution validator added in this PR. - Run clang-format on curve.h and crypto.cpp.
Contributor
There was a problem hiding this comment.
Pull request overview
This PR hardens governance constitution validation for JWT issuers/JWKS inputs, CA certificate bundles, and member encryption keys, and extends crypto support to include P-521 across the JS and C++ crypto surfaces. It updates end-to-end/unit tests and documentation to match the stricter validation rules and new curve support.
Changes:
- Tighten sample constitution validation for JWT issuer URLs, JWKS key material/metadata, CA bundles, and member
encryption_pub_key. - Add P-521 (secp521r1) support across crypto conversion/mapping layers and extend related JS/C++ tests.
- Update test infrastructure and docs to generate/expect HTTPS issuers and CA-capable certificates where required by new validation.
Custom instructions used:
.github/copilot-instructions.md.github/instructions/reviewing.instructions.md
Reviewed changes
Copilot reviewed 17 out of 17 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| tests/npm_tests.py | Extends EC keypair/JWK tests to include P-521. |
| tests/jwt_test.py | Adds negative-coverage tests for stricter JWT issuer URL and JWKS validation. |
| tests/js-custom-authorization/custom_authorization.py | Updates test issuer URL to HTTPS to satisfy new issuer validation. |
| tests/infra/jwt_issuer.py | Switches JWK numeric encoding to base64url and generates CA-capable certs for JWT issuer fixtures. |
| tests/ca_certs.py | Adds rejection/acceptance cases for CA bundle validation (non-CA and intermediate/root bundles). |
| src/js/extensions/ccf/crypto.cpp | Adds secp521r1 mapping support in the JS crypto extension. |
| src/crypto/test/crypto.cpp | Extends PEM↔JWK and COSE-compatibility tests to cover P-521. |
| src/crypto/openssl/ec_public_key.cpp | Adds P-521 OpenSSL curve mapping and fixes coordinate sizing for non-byte-aligned curves. |
| src/crypto/openssl/ec_key_pair.cpp | Fixes private-key coordinate sizing for non-byte-aligned curves (P-521). |
| samples/minimal_ccf/app/actions.js | Adds stricter JWT/JWKS/CA/member-key validation to the minimal sample constitution. |
| samples/constitutions/default/actions.js | Adds stricter JWT/JWKS/CA/member-key validation to the default constitution. |
| js/ccf-app/test/polyfill.test.ts | Adds/extends tests for secp521r1 keygen and PEM↔JWK conversions. |
| js/ccf-app/src/global.ts | Updates public TS typings/docs to mention secp521r1 support. |
| include/ccf/crypto/jwk.h | Enables P-521 JWK curve mapping in C++ helpers. |
| include/ccf/crypto/curve.h | Adds SECP521R1 to the supported curve enum and associated digest mapping. |
| doc/build_apps/auth/jwt.rst | Updates JWT governance examples to use HTTPS issuer URLs. |
| CHANGELOG.md | Documents the strengthened validation behavior and P-521 acceptance. |
Comments suppressed due to low confidence (1)
src/crypto/openssl/ec_public_key.cpp:327
- BN_bn2binpad() return values are ignored when serialising EC public key coordinates. If BN_bn2binpad fails (eg if OpenSSL returns an error), this will silently return incorrect x/y bytes rather than failing fast. Per the repo's third-party error-handling guidance, OpenSSL calls that can fail should have their return values checked (see .github/instructions/reviewing.instructions.md).
int sz = (EC_GROUP_get_degree(group) + CHAR_BIT - 1) / CHAR_BIT;
r.x.resize(sz);
r.y.resize(sz);
BN_bn2binpad(x, r.x.data(), sz);
BN_bn2binpad(y, r.y.data(), sz);
cjen1-msft
reviewed
Jun 9, 2026
cjen1-msft
reviewed
Jun 9, 2026
cjen1-msft
approved these changes
Jun 9, 2026
Member
|
@copilot fix the formatting now. |
Co-authored-by: achamayou <[email protected]>
Contributor
Author
Fixed in 2f2a3d5. All formatting checks now pass (prettier, clang-format, black, ruff). |
Co-authored-by: achamayou <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Constitution validators accepted weak or malformed security inputs, including unsafe JWKS metadata, non-HTTPS JWT issuers, non-root-CA TLS trust anchors, and unchecked member encryption keys. This tightens validation using the existing JS crypto surface where available.
kidvalues.ktytoRSAorEC.usetosig.algto supported signing algorithms (RS256,ES256).x5ccertificate chains to the provided root.JWT issuer validation
auto_refresh.CA bundle validation
set_ca_cert_bundlenow requires every certificate in the bundle to be a self-signed (root) CA. Intermediate CA certificates are rejected even when their signing root is also present in the bundle.isValidX509RootCACertto the JS crypto API (ccf.crypto), backed by a C++ function that checks bothEXFLAG_SS(self-signed) andX509_check_ca, without relying onX509_V_FLAG_PARTIAL_CHAIN.Member encryption key validation
set_membernow validatesencryption_pub_keyas a well-formed RSA public key with minimum strength before storing it.P-521 support
Coverage updates
isValidX509RootCACert(self-signed CA, non-CA self-signed, intermediate CA, malformed input).