Skip to content

Fix nil pointer panics in GitHub analyzer gist/repo binding functions#4864

Merged
shahzadhaider1 merged 5 commits intotrufflesecurity:mainfrom
shahzadhaider1:INS-442-fix-nil-pointer-in-github-analyzer
Apr 17, 2026
Merged

Fix nil pointer panics in GitHub analyzer gist/repo binding functions#4864
shahzadhaider1 merged 5 commits intotrufflesecurity:mainfrom
shahzadhaider1:INS-442-fix-nil-pointer-in-github-analyzer

Conversation

@shahzadhaider1
Copy link
Copy Markdown
Contributor

@shahzadhaider1 shahzadhaider1 commented Apr 3, 2026

Problem

A panic was caught in the GitHub analyzer worker:

runtime error: invalid memory address or nil pointer dereference
github.com/trufflesecurity/trufflehog/v3/pkg/analyzer/analyzers/github.secretInfoToGistBindings
    pkg/analyzer/analyzers/github/github.go:129

The GitHub API returns description and owner as optional nullable fields on gist objects. When a gist has no description, the API returns null, leaving Description as a nil *string. The code dereferenced it directly (*gist.Description) without any nil guard.

The same class of bug existed across several functions in the file: *gist.Owner.Login, *gist.ID, *repo.Name, *repo.FullName, *user.Login, *user.Type; all raw dereferences of fields that the go-github library defines as optional pointers.

Why safe getters alone weren't enough for Owner

For Description, replacing the dereference with GetDescription() (returns "" on nil) is sufficient, a gist without a description is still attributable.

For Owner, falling back to an empty string silently produces corrupt output:

  • FullyQualifiedName: "gist.github.com//abc123": malformed
  • Parent resource with empty Name and Type

A gist with no owner cannot be meaningfully attributed, so it is skipped rather than emitting bad data. This is consistent with how PrintGists in common/github.go already handles nil gist pointers.

Checklist:

  • Tests passing (make test-community)?
  • Lint passing (make lint this requires golangci-lint)?

Note

Medium Risk
Moderate risk because it changes GitHub permission analysis output in edge cases (skipping ownerless gists and emitting repos without a parent), but the changes are localized and add coverage for the nil-field scenarios that previously panicked.

Overview
Prevents nil-pointer panics in the GitHub analyzer by switching to go-github safe getters (GetLogin, GetType, GetName, GetFullName, GetDescription, GetID) when building user/repo/gist resources.

Adjusts binding behavior for missing owners: repositories are still emitted with Parent unset if Owner is nil, while gists with a nil Owner are skipped to avoid generating malformed FullyQualifiedNames. Adds unit tests covering these nil-field edge cases for secretInfoToGistBindings and secretInfoToRepoBindings.

Reviewed by Cursor Bugbot for commit 4383331. Bugbot is set up for automated code reviews on this repo. Configure here.

@shahzadhaider1 shahzadhaider1 requested a review from a team April 3, 2026 21:02
@shahzadhaider1 shahzadhaider1 requested a review from a team as a code owner April 3, 2026 21:02
Copy link
Copy Markdown

@cursor cursor bot left a comment

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 2 potential issues.

Fix All in Cursor

Comment thread pkg/analyzer/analyzers/github/github.go
Comment thread pkg/analyzer/analyzers/github/github_test.go
Copy link
Copy Markdown
Contributor

@MuneebUllahKhan222 MuneebUllahKhan222 left a comment

Choose a reason for hiding this comment

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

LGTM! Just one small comment that we should think over

Comment thread pkg/analyzer/analyzers/github/github.go Outdated
@shahzadhaider1 shahzadhaider1 merged commit 371e227 into trufflesecurity:main Apr 17, 2026
14 checks passed
@shahzadhaider1 shahzadhaider1 deleted the INS-442-fix-nil-pointer-in-github-analyzer branch April 17, 2026 10:41
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.

3 participants