test(amplify-category-auth): generate ephemeral EC key at runtime instead of committed key literal - #14985
Open
Simone319 wants to merge 1 commit into
Open
test(amplify-category-auth): generate ephemeral EC key at runtime instead of committed key literal#14985Simone319 wants to merge 1 commit into
Simone319 wants to merge 1 commit into
Conversation
Contributor
|
Do we need to clean up other occurrences of hardcoded key literals from the repo? |
…tead of committed key literal Secret scanning flags this test file for a committed private-key literal (HARD_CODED_RSA_PRIVATE_KEY_DETECTED / acat-bosco). The committed value is a real, cryptographically valid P-256 (prime256v1) private key: openssl pkey parses it as a 256-bit NIST P-256 key and a sign/verify round trip succeeds. Per the in-repo comments on the sibling copies it was deliberately revoked Apple-side, retained only because it is structurally valid enough to pass Cognito's config-time validation. Not believed to be a live credential, but it is real key material and should not live in source. extractApplePrivateKey needs only a key-shaped string: it strips whitespace and lifts the base64 body out from between the PEM markers, performing no cryptographic validation and no Apple-side lookup. So the test does not need a real or registered key. Generate an ephemeral P-256 key at runtime and derive the expected value from it instead. Both existing assertions are preserved in meaning, and the test now runs against a freshly generated valid key rather than one frozen string. The same key is committed in 8 other files; those feed real E2E runs and are addressed separately via a CI secret. Test-only change; extract-apple-private-key.ts is untouched.
Simone319
force-pushed
the
security/apple-key-runtime-gen
branch
from
September 10, 2026 15:08
981913d to
31f4edf
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Secret scanning (
acat-bosco/rsa-private-key, HARD_CODED_RSA_PRIVATE_KEY_DETECTED) flagspackages/amplify-category-auth/src/__tests__/provider-utils/awscloudformation/utils/extract-apple-private-key.test.tsfor a committed private-key literal.
The committed value is a real, cryptographically valid P-256 (
prime256v1) private key —not a malformed placeholder. Verified:
openssl pkey -inform DERparses it as a 256-bitNIST P-256 key, and a sign→verify round trip succeeds. It is genuine, signature-capable key
material.
Per the in-repo comments accompanying the sibling copies (
sample.env: "the following keysare invalidated but they pass Cognito validation";
envVars.ts: "this is an invalidatedkey"), the key was deliberately revoked/invalidated on the Apple side — it is retained
only because it is structurally valid enough to pass Cognito's config-time validation. So
this is not believed to be a live credential, but it is real key material and should not
be committed to source.
Fix
extractApplePrivateKeyonly needs a key-shaped string — it strips whitespace and pullsthe base64 body out from between the PEM markers. It performs no cryptographic validation, no
algorithm check, and no Apple-side lookup. The test therefore does not need a real or
registered key at all.
Generate an ephemeral P-256 key at runtime (
crypto.generateKeyPairSync, curveprime256v1— the ES256 curve Sign in with Apple uses) once atdescribescope, and derivethe expected value from it via
createPrivateKey(pem).export({ type: 'pkcs8', format: 'der' }).toString('base64').Result: zero static key material in source, nothing for the scanner to match, and no
hardcoded literal or length to drift.
Scope / risk
extract-apple-private-key.tsis unchanged.body, and idempotence for an already-extracted key.
-+marker pattern is dash-count agnostic, so no massaging is required.
Bonus: better coverage
The old fixture was retained purely as a static string, so the test only ever exercised
string munging against one frozen value. It now runs against a freshly generated, valid
P-256 PKCS#8 key on every run.
Not covered by this PR
The same key is committed in 8 other files (9 further occurrences) —
amplify-e2e-core(
envVars.ts,auth-utils.ts),amplify-e2e-tests/sample.env, and 5codebuild_specs/*.yml.Those are addressed separately, since they feed real E2E runs and need a CI-secret
mechanism rather than a generated key.
Verification
jeston this file: 2 passed, 2 total (exit 0). Additionally confirmed the test is notvacuous — against a mutant extractor that skips marker extraction, assertion 1 fails as
expected.