Repository navigation
fix(github): accept escaped newlines in GITHUB_APP_PRIVATE_KEY - #100
Conversation
Mira PR WalkthroughThis PR fixes GitHub App private key handling in the core crate by normalizing escaped Confidence: 5/5 ◉◉◉◉◉ Safe to merge
1 file reviewed · 1 unresolved thread
|
There was a problem hiding this comment.
Mira Review Summary
Single-file fix that normalizes literal \n escapes in GITHUB_APP_PRIVATE_KEY before RSA PEM parsing. The approach is sound — base64 PEM bodies cannot contain a literal backslash, so the replace cannot corrupt a valid key, and applying it inside jwt() covers env, DB, and manifest-registered credentials uniformly. One warning filed: the new normalization logic has no test coverage guarding the exact regression this PR fixes.
| let pem = private_key.replace("\\n", "\n"); | ||
| let key = jsonwebtoken::EncodingKey::from_rsa_pem(pem.as_bytes()) |
There was a problem hiding this comment.
Refactor suggestion
Missing test coverage for escaped-newline PEM normalization
The private_key.replace("\\n", "\n") normalization is the entire behavioral change of this PR — it is what unblocks env-configured GitHub Apps — but no test exercises it. A future refactor (e.g. moving normalization into from_settings, or someone 'simplifying' the replace away) would silently re-break GITHUB_APP_PRIVATE_KEY with escaped newlines, and the failure only surfaces at JWT-signing time in production. A small unit test asserting that a key containing literal \n sequences parses via EncodingKey::from_rsa_pem would lock in the fix.
| let pem = private_key.replace("\\n", "\n"); | |
| let key = jsonwebtoken::EncodingKey::from_rsa_pem(pem.as_bytes()) | |
| // jarvis: env-provided PEMs carry literal \n; normalize once here | |
| let pem = private_key.replace("\\n", "\n"); | |
| let key = jsonwebtoken::EncodingKey::from_rsa_pem(pem.as_bytes()) | |
| .map_err(|e| Error::Config(format!("invalid app private key: {e}")))?; |
Prompt for AI Agents
In crates/core/src/github.rs around line 172, add test coverage for the new PEM normalization: either extract the unescaping into a small helper (e.g. fn normalize_pem(key: &str) -> String that performs key.replace("\\n", "\n")) and unit-test it with inputs containing literal \n escapes, real newlines, and an already-valid PEM, or construct a GithubService with escaped-newline credentials and assert jwt() succeeds. This guards the env-configured GitHub App path that this PR exists to fix.
Apply this code change:
// jarvis: env-provided PEMs carry literal \n; normalize once here
let pem = private_key.replace("\\n", "\n");
let key = jsonwebtoken::EncodingKey::from_rsa_pem(pem.as_bytes())
.map_err(|e| Error::Config(format!("invalid app private key: {e}")))?;
Not useful? Reply
@mira-tdvorak rejectto dismiss this suggestion.
Env-injected PEMs arrive with literal \n escapes (dotenv/compose cannot carry raw newlines); normalize before jsonwebtoken parses the key. Generated with [Devin](https://devin.ai) Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
5e2a735 to
07c8220
Compare
Summary
GITHUB_APP_PRIVATE_KEYarrives through env interpolation with literal\nescapes (dotenv and compose env files can't carry raw newlines); normalize once beforeEncodingKey::from_rsa_pemrunway-deploysapp (ID 5832306): signed webhook → deployment → private-repo clone → 200 →runway/github-e2e-devs-teamcheck run successTouches DESIGN bet: single-binary / env-first config.
Generated with Devin