Repository navigation
feat: publish imported key certificates in JWKS - #3257
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (3)
🚧 Files skipped from review as they are similar to previous changes (3)
📝 WalkthroughWalkthroughAdds certificate input and validation for imported signature keys, derives ChangesImported certificate support
Estimated code review effort: 3 (Moderate) | ~25 minutes Sequence Diagram(s)sequenceDiagram
participant KeyForm
participant KeyService
participant CertificateHelpers
participant JWKSHandlers
KeyForm->>KeyService: submit imported key and certificate
KeyService->>CertificateHelpers: parse chain and match leaf SPKI
CertificateHelpers-->>KeyService: validated certificate chain
JWKSHandlers->>CertificateHelpers: derive x5c and x5t#S256
CertificateHelpers-->>JWKSHandlers: optional certificate JWK fields
JWKSHandlers-->>KeyForm: return JWKS with certificate metadata
Possibly related PRs
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 ESLint
ESLint install timed out. The project may have too many dependencies for the sandbox. 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.
Actionable comments posted: 1
🧹 Nitpick comments (2)
apps/server-core/test/unit/core/entities/key/service.spec.ts (1)
9-9: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueCertificate PEM fixture loading copy-pasted across two spec files. Both specs read the same
certificate.pem/private-key.pem/public-key.pemfiles with identicalreadFileSync(new URL(...))boilerplate.
apps/server-core/test/unit/core/entities/key/service.spec.ts#L9-L9,L29-L41: import CERTIFICATE/PRIVATE_KEY/PUBLIC_KEY from a shared test fixture helper instead of re-reading the files inline.apps/server-core/test/unit/http/controllers/entities/key.spec.ts#L8-L9,L25-L37: same — import from the shared helper.♻️ Proposed fix: shared test fixture module
+// apps/server-core/test/data/certificates/index.ts +import { readFileSync } from 'node:fs'; + +export const CERTIFICATE = readFileSync( + new URL('./certificate.pem', import.meta.url), + 'utf8', +); +export const PRIVATE_KEY = readFileSync( + new URL('./private-key.pem', import.meta.url), + 'utf8', +); +export const PUBLIC_KEY = readFileSync( + new URL('./public-key.pem', import.meta.url), + 'utf8', +);🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@apps/server-core/test/unit/core/entities/key/service.spec.ts` at line 9, Replace the duplicated inline certificate fixture loading in apps/server-core/test/unit/core/entities/key/service.spec.ts (lines 9 and 29-41) and apps/server-core/test/unit/http/controllers/entities/key.spec.ts (lines 8-9 and 25-37) with imports of CERTIFICATE, PRIVATE_KEY, and PUBLIC_KEY from the shared test fixture helper, removing the redundant fs imports and readFileSync/new URL boilerplate in both specs.apps/server-core/src/adapters/http/controllers/workflows/jwks/module.ts (1)
22-48: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winShared
buildCertificateJwkFieldscopy-pasted between the two JWKS surfaces. Both files define byte-identical logic for derivingx5c/x5t#S256and tolerating malformed certificates; the shared root cause is that this security-relevant derivation lives in two places that must be kept in sync by hand.
apps/server-core/src/adapters/http/controllers/workflows/jwks/module.ts#L22-L48: remove the localbuildCertificateJwkFieldsand import a single shared implementation instead.apps/server-core/src/adapters/http/controllers/workflows/jwks/handlers/read.ts#L15-L35: remove the localbuildCertificateJwkFieldsand import the same shared implementation.♻️ Proposed fix: hoist the helper into `core/key/certificate.ts` (already home to `parseCertificateChain`/`buildX5c`/`buildX5tS256`)
+// apps/server-core/src/core/key/certificate.ts +export function buildCertificateJwkFields( + certificate: string | null, +): Partial<Pick<OAuth2JsonWebKey, 'x5c' | 'x5t#S256'>> { + if (!certificate) { + return {}; + } + + try { + const chain = parseCertificateChain(certificate); + return { + x5c: buildX5c(chain), + 'x5t#S256': buildX5tS256(chain), + }; + } catch { + return {}; + } +}-import { buildX5c, buildX5tS256, parseCertificateChain } from '../../../../../core/index.ts'; +import { buildCertificateJwkFields } from '../../../../../core/index.ts'; - -function buildCertificateJwkFields( - certificate: string | null, -): Partial<Pick<OAuth2JsonWebKey, 'x5c' | 'x5t#S256'>> { - if (!certificate) { - return {}; - } - - try { - const chain = parseCertificateChain(certificate); - return { - x5c: buildX5c(chain), - 'x5t#S256': buildX5tS256(chain), - }; - } catch { - return {}; - } -}(apply the same import swap in
handlers/read.ts, adjusting the relative path depth.)🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@apps/server-core/src/adapters/http/controllers/workflows/jwks/module.ts` around lines 22 - 48, Move the shared buildCertificateJwkFields implementation into core/key/certificate.ts alongside parseCertificateChain, buildX5c, and buildX5tS256, preserving its malformed-certificate fallback behavior. Remove the local helper and import the shared implementation in apps/server-core/src/adapters/http/controllers/workflows/jwks/module.ts lines 22-48 and apps/server-core/src/adapters/http/controllers/workflows/jwks/handlers/read.ts lines 15-35, adjusting the relative import path in the latter.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@apps/server-core/src/core/key/certificate.ts`:
- Line 8: Update the imported-key comparison flow in the certificate
key-matching logic around X509Certificate and createHash to parse spkiBase64
with Node’s createPublicKey, then export that parsed key as DER before comparing
it with the certificate’s exported public key. Keep the existing hash or byte
comparison behavior unchanged after both keys use the canonical serialization.
---
Nitpick comments:
In `@apps/server-core/src/adapters/http/controllers/workflows/jwks/module.ts`:
- Around line 22-48: Move the shared buildCertificateJwkFields implementation
into core/key/certificate.ts alongside parseCertificateChain, buildX5c, and
buildX5tS256, preserving its malformed-certificate fallback behavior. Remove the
local helper and import the shared implementation in
apps/server-core/src/adapters/http/controllers/workflows/jwks/module.ts lines
22-48 and
apps/server-core/src/adapters/http/controllers/workflows/jwks/handlers/read.ts
lines 15-35, adjusting the relative import path in the latter.
In `@apps/server-core/test/unit/core/entities/key/service.spec.ts`:
- Line 9: Replace the duplicated inline certificate fixture loading in
apps/server-core/test/unit/core/entities/key/service.spec.ts (lines 9 and 29-41)
and apps/server-core/test/unit/http/controllers/entities/key.spec.ts (lines 8-9
and 25-37) with imports of CERTIFICATE, PRIVATE_KEY, and PUBLIC_KEY from the
shared test fixture helper, removing the redundant fs imports and
readFileSync/new URL boilerplate in both specs.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: e2710016-191a-41ed-8189-909bd9280e1b
⛔ Files ignored due to path filters (4)
apps/server-core/test/data/certificates/certificate.pemis excluded by!**/*.pemapps/server-core/test/data/certificates/private-key.pemis excluded by!**/*.pemapps/server-core/test/data/certificates/public-key.pemis excluded by!**/*.pemapps/server-core/test/data/certificates/secondary-certificate.pemis excluded by!**/*.pem
📒 Files selected for processing (18)
.agents/architecture.mdapps/server-core/src/adapters/http/controllers/workflows/jwks/handlers/read.tsapps/server-core/src/adapters/http/controllers/workflows/jwks/module.tsapps/server-core/src/core/entities/key/service.tsapps/server-core/src/core/key/certificate.tsapps/server-core/src/core/key/index.tsapps/server-core/test/unit/core/entities/key/service.spec.tsapps/server-core/test/unit/core/key/certificate.spec.tsapps/server-core/test/unit/http/controllers/entities/key.spec.tspackages/client-web-kit/src/components/entities/key/AKeyForm.vuepackages/core-http-kit/src/domains/entities/key/types.tspackages/core-kit/src/domains/key/validator.tspackages/i18n/src/catalogs/de/field.tspackages/i18n/src/catalogs/en/field.tspackages/i18n/src/catalogs/es/field.tspackages/i18n/src/catalogs/fr/field.tspackages/i18n/src/constants.tspackages/specs/src/oauth2/types.ts
authup
@authup/client-web
@authup/server-core
@authup/access
@authup/client-web-kit
@authup/client-web-kit-theme
@authup/client-web-nuxt
@authup/client-web-theme
@authup/core-http-kit
@authup/core-kit
@authup/core-realtime-kit
@authup/errors
@authup/i18n
@authup/kit
@authup/server-adapter-kit
@authup/server-adapter-node
@authup/server-adapter-socket-io
@authup/server-adapter-web
@authup/server-kit
@authup/server-test-kit
@authup/specs
commit: |
Summary
x5cand SHA-256x5t#S256metadata on global and realm JWKS collection/item endpoints, while keeping malformed stored certificate data from breaking JWKS readsTesting
specs,core-kit,i18n,core-http-kit,client-web-kitapps/server-corebuild and type checkgrant-refresh-token.spec.ts, whose isolated rerun passed 14/14Notes
auth_keys.certificatecolumn; no migration is requiredSummary by CodeRabbit
x5c) and SHA-256 thumbprint (x5t#S256) when certificates are provided and applicable.