GeezerVison is showing github.com — projector(github): GITHUB_APP_PRIVATE_KEY 'base64 of PEM' form fails — decodePem never unwraps it, appJwt throws Invalid keyData · Issue #1529 · developing-today/code
projector(github): GITHUB_APP_PRIVATE_KEY 'base64 of PEM' form fails — decodePem never unwraps it, appJwt throws Invalid keyData #1529Descriptionprojector: GITHUB_APP_PRIVATE_KEY documented "base64 of PEM" form fails — decodePem never unwraps it
Summary
pm-stack/projector/src/github.ts documents GITHUB_APP_PRIVATE_KEY as "PEM (or base64 of PEM)" (line 6), but the base64-of-PEM form does not work: appJwt throws Invalid keyData at key import. Only raw PEM text and base64-of-DER actually work today, and the tests only cover base64-of-DER — so the documented input form most operators would produce (base64-encoding the .pem file GitHub gives them, e.g. for a one-line env var) is silently broken.
Evidence
decodePem (github.ts:16-23):
function decodePem(pem: string): string {
const trimmed = pem.replace(/-----[^-]+-----/g, "").replace(/\s/g, "");
if (/^[A-Za-z0-9+/]+=*$/.test(trimmed) && !trimmed.includes("PRIVATE")) {
// already base64 of the DER key
return trimmed;
}
return trimmed;
}
Trace for base64-of-PEM input:
- Input is base64 of the whole PEM text — it contains no
----- markers, so the strip is a no-op; the string is pure base64, so the regex branch returns it unchanged.
appJwt (github.ts:66-67) then does a single Buffer.from(b64, "base64") — which yields the PEM text bytes, not DER.
importRsaKey feeds those ASCII bytes to WebCrypto as PKCS#8 (and then as PKCS#1-wrapped) → both fail with "Invalid keyData".
Verified behavior (reproduced on the laptop against the current code):
- plain PEM text → works (header/footer stripped, body is the DER base64)
- base64 of DER → works
- base64 of PEM → FAIL
Invalid keyData
Test gap: pm-stack/projector/test/github.test.ts:5-9 builds its "key formats" fixtures by exporting DER and base64-encoding that (privateKey.export({ type, format: "der" })). No fixture ever passes PEM text or base64-of-PEM, so the documented contract is untested in exactly the form that's broken.
Why it matters
The projector's GitHub App auth is how it self-heals beyond webhook delivery. An operator who follows the header comment and stores the key base64-encoded (the standard way to put a PEM in an env var or secret store) gets a projector that cannot authenticate at all, with an error that points at the key data rather than the encoding — the worst kind of config failure to diagnose.
Acceptance criteria
appJwt succeeds with all three input forms of the same key: raw PEM text, base64 of DER, and base64 of PEM (both PKCS#1 "RSA PRIVATE KEY" and PKCS#8 PEM variants).
- Fix direction: make
decodePem actually decode — if the input is base64 whose decoded text starts with -----BEGIN, treat the decoded text as PEM and extract its body (one recursive/iterative unwrap is enough); keep the existing DER and raw-PEM behavior unchanged.
- Tests in
test/github.test.ts cover PEM-text and base64-of-PEM fixtures (generate the key, export format: "pem", pass it raw and base64-encoded) alongside the existing DER controls.
- No change to the env var names or the documented contract — the code is brought up to the doc, not the other way around.
Notes
- Found by new-issue-creator-code-b (run 2026-10-27 15:20 CDT), which verified the reproduction but timed out before filing; filed by the coordinator from its verified report and re-checked against source at github.ts:6,16-23,66-67 and test/github.test.ts:5-20.
- Dedup:
gh issue search (open + closed) for decodePem, base64 PEM, GITHUB_APP_PRIVATE_KEY in this repo returned no existing issue.
Activitydeveloping-today commented on Oct 28, 2026 dezren39 commented on Oct 28, 2026 🤖 Agent note · filed
- Agent: new-issue-creator job (lane B, slug new-issue-creator-code-b) — verification by the lane-B run; filing completed by the coordinator after that run timed out pre-filing
- Session / ID: cron job new-issue-creator-code-b, run 2026-10-27 15:20 CDT (filing completed 2026-10-27 ~19:02 CDT)
- Found via: filed this run
- Task: Filed after verifying that pm-stack/projector/src/github.ts decodePem (:16-23) never unwraps base64-of-PEM: the documented GITHUB_APP_PRIVATE_KEY form "PEM (or base64 of PEM)" (github.ts:6) base64-decodes once in appJwt (:66-67) to PEM text, which WebCrypto then rejects as Invalid keyData. Reproduced on the laptop: plain PEM OK, base64-of-DER OK, base64-of-PEM FAIL. Tests (test/github.test.ts:5-20) only ever feed base64-of-DER fixtures, so the documented form is untested. Enqueued as a triage packet to repo-health-code-pilot.
- Expectation: triage (effort s) confirms and routes the fix: decodePem unwraps base64-of-PEM (decode → PEM text → strip body), existing forms unchanged, PEM-text and base64-of-PEM fixtures added to test/github.test.ts for both PKCS#1 and PKCS#8.
- Links: packet hidden_files/packet-1529.json · body hidden_files/issue-code-projector-decodepem-b64pem-body.md
dezren39 commented on Oct 31, 2026 dezren39 commented on Oct 31, 2026 🤖 Agent note · done — fixed & merged
- Agent: queue worker (repo-worker-code), openchamber scheduled lane
- Session / ID: queue task 1804 (small_fix)
- Fix: PR fix(projector): unwrap base64-of-PEM in decodePem (#1529) #2921 merged as 48f7c86 — decodePem single-unwrap of base64-of-PEM; raw-PEM and base64-of-DER byte-identical
- Tests: github.test.ts 8/8 pass (4 new PEM fixtures); full suite delta clean vs origin/main (libsql dep failures pre-existing, unrelated)
- Labels: removed work/assigned, queue/claimed, status/in-progress (terminal state)
MetadataMetadataDevelopmentNo branches or pull requestsIssue actions
|