Skip to content

Add xAI analyzer - #5456

Merged
dustin-decker merged 2 commits into
trufflesecurity:mainfrom
serval-frenchie:feat/xai-analyzer
Oct 24, 2026
Merged

dustin-decker merged 2 commits into
trufflesecurity:mainfrom
serval-frenchie:feat/xai-analyzer

Conversation

@serval-frenchie

@serval-frenchie serval-frenchie commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

Description:

Closes #5455.

Adds an analyzer for xAI API keys. Today a live xAI key shows "We do not have an analyzer for this secret type yet!" This analyzer reports what the key belongs to and which xAI endpoints and models it can call.

How it works (read-only GET requests only):

  • GET https://api.x.ai/v1/api-key returns the key's name, ID, redacted key, team, user, creation and modification times, api_key_blocked, api_key_disabled, team_blocked, and its ACLs. These all go into the result metadata.
  • ACLs of the form api-key:endpoint:<name> become endpoint_access bindings, and ACLs of the form api-key:model:<name> become model_access bindings. Both sit under a team parent resource, and * is kept as a wildcard resource. Any other ACL form is listed as unrecognized in the CLI output, not mapped to a permission.
  • GET https://api.x.ai/v1/models supplies the model list, filtered by the model ACLs. Models match by ID or alias, and * allows every listed model. If the key may not list models (403/404), the models named in its ACLs are reported instead.
  • A key that is blocked or disabled, or whose team is blocked, returns Valid_Key: false with no bindings. This follows the detector change proposed in fix: xAI detector - verified api key condition #5374.

Files:

  • pkg/analyzer/analyzers/xai/: analyzer, requests, permissions.yaml (endpoint_access, model_access) and the generated permissions.go
  • pkg/analyzer/analyzers/analyzers.go: new AnalyzerTypeXAI ("XAI")
  • pkg/analyzer/cli.go: xai case. The TUI default single-key form already fits, so the TUI needs no change.

Tests:

  • TestAnalyzePermissions uses a stub transport, with no network or credentials. It covers wildcard ACLs, alias matching, ACL-only models, a 403 from /v1/models, blocked keys, disabled keys, 401, and unexpected status codes.
  • TestAnalyzer_Analyze follows the other analyzers: it reads XAI / XAI_INACTIVE from the detectors5 test secret, the same fields pkg/detectors/xai uses. I don't have access to those secrets, so this test checks the result's shape rather than comparing against a recorded result_output.json. I can switch it to a recorded output if a maintainer can capture one.

I haven't run this against a live xAI key, and xAI's docs give only the api-key:endpoint:* and api-key:model:* ACL examples. If real keys carry other ACL shapes, they will show up as unrecognized rather than being dropped.

Checklist:

  • Tests passing (make test-community)? Every package passed except pkg/gitparse, whose TestLowMemoryScanMatchesSingleProcess/abbreviated timed out locally. That package doesn't depend on pkg/analyzer. The new pkg/analyzer/analyzers/xai unit tests pass too; test-community excludes that directory.
  • Lint passing (make lint this requires golangci-lint)? golangci-lint v2.14.0 with the scripts/lint.sh args reports 0 issues on ./pkg/analyzer/....

🤖 Generated with Claude Code


Note

Low Risk
Isolated new analyzer code with read-only external API calls; no changes to existing auth or scanning paths beyond registering the new type and CLI case.

Overview
Adds xAI as a new secret analyzer so discovered xAI API keys can be analyzed for team context, validity, and fine-grained access instead of showing “no analyzer” for that secret type.

The analyzer issues read-only GET calls to xAI’s /v1/api-key and /v1/models endpoints, maps api-key:endpoint:* and api-key:model:* ACLs into endpoint_access / model_access bindings under a team parent, and treats blocked, disabled, or team-blocked keys as Valid_Key: false with no bindings. When model listing is forbidden, it falls back to models named in the ACLs; unrecognized ACL shapes are surfaced in CLI output only.

Wiring includes AnalyzerTypeXAI in the shared enum, an analyze CLI xai branch, generated permissions from permissions.yaml, and unit tests (stubbed HTTP plus optional live keys from test secrets).

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

Reads key metadata from GET /v1/api-key and turns the key's
api-key:endpoint:<name> and api-key:model:<name> ACLs into endpoint and
model bindings under the owning team. Models come from GET /v1/models,
filtered by the model ACLs (matching ids or aliases); when the key may not
list models, the models named in the ACLs are reported instead. Blocked or
disabled keys, and keys of blocked teams, are reported as not valid.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@serval-frenchie
serval-frenchie marked this pull request as ready for review October 21, 2026 17:50
@serval-frenchie
serval-frenchie requested a review from a team October 21, 2026 17:50
@serval-frenchie
serval-frenchie requested a review from a team as a code owner October 21, 2026 17:50
The xAI API key endpoint does not return an expiry, so the analyzer
cannot claim the key never expires.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@dustin-decker
dustin-decker merged commit f6984be into trufflesecurity:main Oct 24, 2026
15 checks passed
@dustin-decker

Copy link
Copy Markdown
Contributor

Thanks mate

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.

Add an analyzer for xAI API keys

2 participants