Skip to content

fix: handle user certificate without certificate policies extension - #131

Merged
mrts merged 1 commit into
web-eid:mainfrom
ErkoRisthein:fix/missing-certificate-policies-extension
Sep 25, 2026
Merged

mrts merged 1 commit into
web-eid:mainfrom
ErkoRisthein:fix/missing-certificate-policies-extension

Conversation

@ErkoRisthein

Copy link
Copy Markdown
Contributor

SubjectCertificatePolicyValidator passed the extension value straight to JcaX509ExtensionUtils.parseExtensionValue(), which throws NullPointerException when the certificate has no certificate policies extension. As the policy check runs before the trust and signature checks, any client could trigger it by presenting a self-signed certificate without the extension, and the NullPointerException escaped the AuthTokenException hierarchy that callers handle.

A certificate without the extension does not contain disallowed policies, so validation now continues to the trust check, matching the behaviour of the .NET validation library.

Signed-off-by: Erko Risthein erko@risthein.ee

Copilot AI lite review requested due to automatic review settings September 4, 2026 05:48

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

The fix is narrowly scoped, prevents the documented exception escape path, and is covered by targeted unit and integration-level tests.

Pull request overview

This PR fixes a certificate-policy validation edge case where certificates lacking the Certificate Policies extension could trigger a NullPointerException, allowing untrusted/self-signed inputs to bypass the expected AuthTokenException error hierarchy and short-circuit validation before trust/signature checks.

Changes:

  • Add a null-guard in SubjectCertificatePolicyValidator so missing Certificate Policies extension is treated as “no disallowed policies”.
  • Add unit tests covering both the policy-validator behavior and end-to-end validator behavior (continues to trust check).
  • Extend test certificate utilities with a dedicated certificate fixture that lacks the Certificate Policies extension.
File summaries
File Description
src/main/java/eu/webeid/security/validator/certvalidators/SubjectCertificatePolicyValidator.java Prevents NPE by explicitly handling missing Certificate Policies extension and allowing validation to proceed.
src/test/java/eu/webeid/security/validator/certvalidators/SubjectCertificatePolicyValidatorTest.java Adds focused tests for allowed/disallowed policies and missing-extension behavior.
src/test/java/eu/webeid/security/validator/AuthTokenCertificateTest.java Adds an integration-style regression test ensuring missing extension flows to trust validation.
src/test/java/eu/webeid/security/testutil/Certificates.java Adds a reusable test certificate fixture without the Certificate Policies extension.
Review details
  • Files reviewed: 4/4 changed files
  • Comments generated: 0
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@kristelmerilain

Copy link
Copy Markdown
Contributor

Thank you for your contribution!

We’ll test the changes and review the code in the near future. If everything looks as expected, then we plan to include and publish this as part of the 4.0.0 release.

@mrts

mrts commented Sep 25, 2026

Copy link
Copy Markdown
Member

@ErkoRisthein, thanks a lot for your contribution! This is now tested and ready to merge. Can you please rebase to latest main and add a Signed-off-by tag to your commit as explained in contributing guide to conform to Certificate of Origin v1.1?

SubjectCertificatePolicyValidator passed the extension value straight to
JcaX509ExtensionUtils.parseExtensionValue(), which throws
NullPointerException when the certificate has no certificate policies
extension. As the policy check runs before the trust and signature
checks, any client could trigger it by presenting a self-signed
certificate without the extension, and the NullPointerException escaped
the AuthTokenException hierarchy that callers handle.

A certificate without the extension does not contain disallowed
policies, so validation now continues to the trust check, matching the
behaviour of the .NET validation library.

Signed-off-by: Erko Risthein <erko@risthein.ee>
@ErkoRisthein
ErkoRisthein force-pushed the fix/missing-certificate-policies-extension branch from bbfa8bd to e232d91 Compare September 25, 2026 19:53
@mrts
mrts merged commit 55674bc into web-eid:main Sep 25, 2026
4 of 5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants