Skip to content

fix: sanitize keys with optional PEM fields - #2327

Open
pcbeingused333 wants to merge 2 commits into
Kong:mainfrom
pcbeingused333:fix/sanitize-optional-pem
Open

pcbeingused333 wants to merge 2 commits into
Kong:mainfrom
pcbeingused333:fix/sanitize-optional-pem

Conversation

@pcbeingused333

Copy link
Copy Markdown

Sanitizing a key with only a public or private PEM field panics because handleKey dereferences both optional input fields when recording their sanitized values. Kong accepts either field on its own.

Only populate sanitized PEM fields that are present in the input, and guard each map insertion with a nil check. The existing replacement key pair generation remains unchanged. Add regression coverage through NewSanitizer for public-only, private-only, and complete PEM inputs, checking that supplied values are replaced and recorded consistently and absent fields stay nil.

Testing: on current main (387ed97), the regression fails with nil-pointer panics in both single-field cases (2 failures, 1 pass). With this fix all 3 cases pass. The entire sanitize package also passes. The targeted command is GOTOOLCHAIN=local go test ./sanitize -run Test_SanitizeKeyOptionalPEM -count=1. Formatting and git diff --check pass.

This change was prepared with AI assistance (OpenAI Codex).

This branch has not been deployed

No deployments
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.

1 participant