Skip to content

fix: omit KeyInfo when there is no content for it - #597

Merged
cjbarth merged 1 commit into
node-saml:masterfrom
cjbarth:fix/keyinfo-without-content
Sep 15, 2026
Merged

cjbarth merged 1 commit into
node-saml:masterfrom
cjbarth:fix/keyinfo-without-content

Conversation

@cjbarth

@cjbarth cjbarth commented Sep 15, 2026

Copy link
Copy Markdown
Contributor

Closes #596

XMLDSig's schema requires KeyInfo (4.5) and X509Data (4.5.4) to each contain at least one child element. Signing could produce either one empty:

Configuration Before After
publicCert has no BEGIN CERTIFICATE block, e.g. a PEM public key <KeyInfo><X509Data/></KeyInfo> no KeyInfo
keyInfoAttributes set, no publicCert <KeyInfo Id="key">null</KeyInfo> no KeyInfo

Changes

  • SignedXml.getKeyInfoContent returns null when publicCert contains no certificate. Its JSDoc already defines null as "no KeyInfo element should be included".
  • getKeyInfo() emits KeyInfo only when getKeyInfoContent returns content. keyInfoAttributes alone no longer produce an element.
  • The README's extension-point section says what happens when there is no content.

Compatibility

This targets v6.2 and does not throw. The issue notes that throwing when keyInfoAttributes are set with no content would be more explicit, but it would break configurations that sign today, so that choice is left for 7.0.

A caller who set keyInfoAttributes with no content and added a reference to KeyInfo now gets the existing "xpath cannot be signed because it was not found" error instead of a signature over <KeyInfo>null</KeyInfo>.

Tests

Two regression tests sign with each configuration and check that the signature has no KeyInfo. Both failed before the fix because a KeyInfo element was present.

🤖 Generated with Claude Code

XMLDSig requires KeyInfo and X509Data to each have at least one child
element. The default getKeyInfoContent returned an empty X509Data when
publicCert held no certificate, and setting keyInfoAttributes without
any content wrote the text "null" into KeyInfo.

Closes node-saml#596

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@cjbarth cjbarth added this to the v6.2 milestone Sep 15, 2026
@cjbarth cjbarth added the bug label Sep 15, 2026
@coderabbitai

coderabbitai Bot commented Sep 15, 2026

Copy link
Copy Markdown

Warning

Review limit reached

Next included review available in 2 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used all 2 included reviews currently available.

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

Learn how review limits work.

Review configuration:

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Advanced

Run ID: 1ec7da3b-0309-453f-a8cf-4ae8ce834f91

📥 Commits

Reviewing files that changed from the base of the PR and between fb8e7c6 and 7633e4d.

📒 Files selected for processing (3)
  • README.md
  • src/signed-xml.ts
  • test/signature-unit-tests.spec.ts

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

Comment @coderabbitai help to get the list of available commands.

@codecov

codecov Bot commented Sep 15, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 79.96%. Comparing base (f5c4d22) to head (7633e4d).
⚠️ Report is 20 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #597      +/-   ##
==========================================
+ Coverage   75.95%   79.96%   +4.01%     
==========================================
  Files           9        9              
  Lines        1048     1118      +70     
  Branches      273      283      +10     
==========================================
+ Hits          796      894      +98     
+ Misses        144      129      -15     
+ Partials      108       95      -13     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@cjbarth
cjbarth merged commit d2aee9b into node-saml:master Sep 15, 2026
13 checks passed
@cjbarth
cjbarth deleted the fix/keyinfo-without-content branch September 15, 2026 00:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Generated KeyInfo can be an empty X509Data or contain the text null

1 participant