Added support for new GitHub App tokens#213
Conversation
|
Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits. |
Gemini ReviewThe PR successfully adds support for the new GitHub App JWT token format, but contains a critical regex bug that will cause false negatives and a likely compilation error in the tests. Critical Issues
SecurityNo security concerns flagged. Suggestions
Reviewed by Gemini (gemini-3.1-pro-preview) · 1 non-code file(s) skipped |
WalkthroughThis pull request adds detection for GitHub App installation tokens in JWT format. A new detection rule ( ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (2)
pkg/validator/github_app.go (1)
13-40: Update the validator doc comment for the new rule.The implementation now supports both
np.github.3andnp.github.8, but the type comment still says this validator handlesnp.github.3only. That wording is stale and will trip up the next person reading the file.♻️ Suggested doc update
-// GitHubAppTokenValidator validates GitHub App tokens (np.github.3). +// GitHubAppTokenValidator validates GitHub App tokens for np.github.3 and np.github.8. // -// np.github.3 matches both ghu_ (user-to-server) and ghs_ (server-to-server) -// tokens. These require different validation endpoints: +// np.github.3 covers the legacy ghu_/ghs_ token formats, while np.github.8 +// covers the new JWT-format ghs_ installation tokens. These require different +// validation endpoints:🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@pkg/validator/github_app.go` around lines 13 - 40, Update the type doc comment for GitHubAppTokenValidator to reflect that it validates both np.github.3 and np.github.8 (not just np.github.3), and briefly describe the dual behavior for ghu_ (user-to-server) and ghs_ (server-to-server/installation) tokens and the different validation endpoints used (GET /user for ghu_ and GET /installation/repositories for ghs_); reference the GitHubAppTokenValidator type and its CanValidate method to ensure the comment aligns with the runtime support for both rule IDs.pkg/validator/github_app_test.go (1)
27-51: Add one end-to-endValidatetest for the JWT-format token.The new
np.github.8coverage currently checks extraction and the no-token path, but it never drivesValidate(...)with a real JWT-formatghs_...sample. A small HTTP-mocked test would close that gap.♻️ Suggested test skeleton
+func TestGitHubAppTokenValidator_GHS_JWT_Validate(t *testing.T) { + jwtToken := "ghs_123456_eyJhbGciOiJSUzI1NiJ9.eyJpc3MiOiJhcHBfaWQifQ.signature_here" + server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + assert.Equal(t, "/installation/repositories", r.URL.Path) + w.WriteHeader(http.StatusOK) + })) + defer server.Close() + + v := NewGitHubAppTokenValidatorWithClient(server.Client()) + match := &types.Match{ + RuleID: "np.github.8", + NamedGroups: map[string][]byte{ + "token": []byte(jwtToken), + }, + } + + result, err := v.Validate(t.Context(), match) + require.NoError(t, err) + assert.Equal(t, types.StatusValid, result.Status) +}🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@pkg/validator/github_app_test.go` around lines 27 - 51, Add an end-to-end test that exercises GitHubAppTokenValidator.Validate with a JWT-format token: create a test similar to TestGitHubAppTokenValidator_GHS_JWT_ExtractToken that constructs a match with RuleID "np.github.8" and NamedGroups["token"] set to a "ghs_..." JWT-style string, start an httptest.Server that mocks the GitHub installation/token endpoint and returns a successful JSON response, configure the validator to use that server (so NewGitHubAppTokenValidator / the validator's HTTP client points to the mock), call v.Validate(t.Context(), match) and assert no error and that result.Status equals types.StatusAllowed; also assert the mock server received the expected request path/headers to ensure the JWT route was used (use extractToken and NewGitHubAppTokenValidator to locate behavior to test).
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@pkg/validator/github_app_test.go`:
- Around line 27-51: Add an end-to-end test that exercises
GitHubAppTokenValidator.Validate with a JWT-format token: create a test similar
to TestGitHubAppTokenValidator_GHS_JWT_ExtractToken that constructs a match with
RuleID "np.github.8" and NamedGroups["token"] set to a "ghs_..." JWT-style
string, start an httptest.Server that mocks the GitHub installation/token
endpoint and returns a successful JSON response, configure the validator to use
that server (so NewGitHubAppTokenValidator / the validator's HTTP client points
to the mock), call v.Validate(t.Context(), match) and assert no error and that
result.Status equals types.StatusAllowed; also assert the mock server received
the expected request path/headers to ensure the JWT route was used (use
extractToken and NewGitHubAppTokenValidator to locate behavior to test).
In `@pkg/validator/github_app.go`:
- Around line 13-40: Update the type doc comment for GitHubAppTokenValidator to
reflect that it validates both np.github.3 and np.github.8 (not just
np.github.3), and briefly describe the dual behavior for ghu_ (user-to-server)
and ghs_ (server-to-server/installation) tokens and the different validation
endpoints used (GET /user for ghu_ and GET /installation/repositories for ghs_);
reference the GitHubAppTokenValidator type and its CanValidate method to ensure
the comment aligns with the runtime support for both rule IDs.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: ebbc84c6-4a17-43a9-adce-ae993606a3f0
📒 Files selected for processing (5)
pkg/rule/rules/github.ymlpkg/rule/rulesets/default.ymlpkg/validator/github_app.gopkg/validator/github_app_test.gotestdata/secrets/github-tokens.txt
michaelweber
left a comment
There was a problem hiding this comment.
This looks reasonable.
Implementing a new rule for the new GitHub App token format. See: https://github.blog/changelog/2026-04-24-notice-about-upcoming-new-format-for-github-app-installation-tokens/