-
Couldn't load subscription status.
- Fork 190
Respect idAttribute when generating signatures. #508
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
|
Not sure if this needs enhancements to provide support for namespaced id's but then the whole idAttribute has to be changed. But in the long run this can then make the idMode parameter obsolete ... |
|
@tkalmar , can you add a test showing how this behavior is currently broken? |
WalkthroughThe pull request enables customizable ID attribute naming in the SignedXml API by replacing the hardcoded "Id" attribute with the configurable Changes
Sequence DiagramN/A Estimated code review effort🎯 1 (Trivial) | ⏱️ ~5 minutes
Possibly related PRs
Suggested labels
Poem
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (2)
src/signed-xml.ts (1)
1332-1332: Consider validating the idAttribute value in the constructor.The change correctly uses
this.idAttributes[0]to respect custom ID attributes. However, there's no validation when a customidAttributeis provided in the constructor (lines 155-157). Invalid values (empty string, whitespace, invalid XML name characters) could cause issues during signing.Consider adding validation in the constructor:
if (idAttribute) { + if (typeof idAttribute !== 'string' || !idAttribute.trim()) { + throw new Error('idAttribute must be a non-empty string'); + } this.idAttributes.unshift(idAttribute); }test/signature-unit-tests.spec.ts (1)
88-88: Fix TypeScript formatting.Type annotations should have spaces around the colon and type union operator.
Apply this diff:
- function verifyAddsId(mode, nsMode, idAttribute:string|undefined = undefined) { + function verifyAddsId(mode, nsMode, idAttribute: string | undefined = undefined) {
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
src/signed-xml.ts(1 hunks)test/signature-unit-tests.spec.ts(2 hunks)
🧰 Additional context used
🧠 Learnings (2)
📓 Common learnings
Learnt from: shunkica
PR: node-saml/xml-crypto#506
File: src/signed-xml.ts:1159-1159
Timestamp: 2025-10-22T21:03:38.354Z
Learning: In node-saml/xml-crypto PR #506, the maintainer (shunkica) requested an issue to separate the overloaded Reference interface into distinct SigningReference and ValidationReference types. Initial hypothesis: signing-only (xpath, isEmptyUri, id, type), validation-only (uri, digestValue, validationError, signedReference), shared (transforms, digestAlgorithm, inclusiveNamespacesPrefixList). This should be proposed and designed in a follow-up, not altered in the current PR.
📚 Learning: 2025-10-22T21:50:05.454Z
Learnt from: shunkica
PR: node-saml/xml-crypto#0
File: :0-0
Timestamp: 2025-10-22T21:50:05.454Z
Learning: In src/signed-xml.ts Line 1099, createReferences mutates ref.uri = id during signing. Maintain this behavior for now; remove/refactor in a separate PR as previously requested by the maintainer.
Applied to files:
test/signature-unit-tests.spec.tssrc/signed-xml.ts
🧬 Code graph analysis (1)
test/signature-unit-tests.spec.ts (1)
src/signed-xml.ts (1)
SignedXml(30-1422)
🔇 Additional comments (1)
test/signature-unit-tests.spec.ts (1)
125-127: Good test coverage for custom ID attributes.The new test case effectively verifies that custom
idAttributevalues are respected during signing, using 'myIdAttribute' to ensure the generated IDs use the configured attribute name instead of the default 'Id'.
|
The code looks OK @tkalmar , but I'm not sure what the use-case is. What is the problem that is solved by writing a different attribute for ID other than the traditional |
|
@cjbarth we are working with an customer endpoint which validates our signed xml, at the moment we have to replace |
|
So, you don't want a different ID, you want a namespace. Do you have a sample XML that you could share? A proper fix would probably be to read the namespace from the existing XML and use that. |
|
The proper solution would be to make idAttribute/idAttributes of type |
Fixes #33
small fix to respect user provided idAttribute when generating id's
Summary by CodeRabbit