Skip to content

fix(github): accept escaped newlines in GITHUB_APP_PRIVATE_KEY - #100

Merged
Dvorinka merged 1 commit into
mainfrom
fix/gh-app-pem-escapes
Nov 19, 2026
Merged

Dvorinka merged 1 commit into
mainfrom
fix/gh-app-pem-escapes

Conversation

@Dvorinka

Copy link
Copy Markdown
Owner

Summary

  • GITHUB_APP_PRIVATE_KEY arrives through env interpolation with literal \n escapes (dotenv and compose env files can't carry raw newlines); normalize once before EncodingKey::from_rsa_pem
  • Unblocks env-configured GitHub Apps — verified live with the runway-deploys app (ID 5832306): signed webhook → deployment → private-repo clone → 200 → runway/github-e2e-devs-team check run success

Touches DESIGN bet: single-binary / env-first config.

Generated with Devin

@mira-tdvorak

mira-tdvorak Bot commented Nov 19, 2026 •

Copy link
Copy Markdown

Mira PR Walkthrough

This PR fixes GitHub App private key handling in the core crate by normalizing escaped \n sequences in the GITHUB_APP_PRIVATE_KEY env var into real newlines before PEM parsing. Previously, env interpolation (dotenv/compose) delivered the key with literal backslash-n escapes, which broke EncodingKey::from_rsa_pem; the fix unblocks fully env-configured GitHub Apps, verified with a live signed-webhook deployment flow.

Confidence: 5/5   ◉◉◉◉◉   Safe to merge
  • Tiny, well-scoped normalization fix that unblocks env-configured GitHub Apps and was verified end-to-end.

1 file reviewed · 1 unresolved thread


💡 This review will be more accurate after indexing. This repo hasn't been indexed yet, so the review is based on the diff plus on-demand file lookups. Visit the Mira dashboard to index this repo — Mira will then know about callers, dependents, and cross-repo impact.


Comment @mira-tdvorak help to get the list of available commands and usage tips.

@mira-tdvorak mira-tdvorak Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread crates/core/src/github.rs
Comment on lines +172 to +173
let pem = private_key.replace("\\n", "\n");
let key = jsonwebtoken::EncodingKey::from_rsa_pem(pem.as_bytes())

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Refactor suggestion
⚠️ Warning

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.

Suggested change
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 reject to 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>
@Dvorinka
Dvorinka force-pushed the fix/gh-app-pem-escapes branch from 5e2a735 to 07c8220 Compare November 19, 2026 13:29
@Dvorinka
Dvorinka merged commit b0daab6 into main Nov 19, 2026
2 checks passed
@Dvorinka
Dvorinka deleted the fix/gh-app-pem-escapes branch November 19, 2026 14:03
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