Fix: Use correct API token for /v0/purl requests#918
Merged
Conversation
When getAlertsMapFromPurls is called without an explicit apiToken option, it was defaulting to getPublicApiToken() which always returns the public token as a fallback. This caused /v0/purl API requests to use the public token even when SOCKET_CLI_API_TOKEN was set in the environment. The fix removes the default value and lets setupSdk handle token resolution through getDefaultApiToken(), which properly respects SOCKET_CLI_API_TOKEN and other token sources.
Created dedicated test file src/utils/alerts-map.test.mts to verify the token selection fix in getAlertsMapFromPurls(). Tests verify: - setupSdk receives undefined when no apiToken provided, allowing proper token resolution through getDefaultApiToken() - setupSdk receives custom token when explicitly provided - Empty purls array returns empty map without calling setupSdk - PURLs are processed and alerts map is returned - Filter options are handled correctly These tests ensure the public token is never incorrectly used when a user-provided token is available in the environment.
billxinli
approved these changes
Nov 18, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixed token selection in
getAlertsMapFromPurls()to respectSOCKET_CLI_API_TOKENinstead of defaulting to public token.Changes
getPublicApiToken()default, letsetupSdk()handle token resolutionNote
Stop defaulting to a public token in
getAlertsMapFromPurls, lettingsetupSdkresolve the token; add unit tests for token passing and PURL processing.getAlertsMapFromPurls: removegetPublicApiTokendefault and pass throughapiTokentosetupSdk.src/utils/alerts-map.test.mtscovering token passing (undefined vs provided), empty PURLs, processing flow, and filter options.Written by Cursor Bugbot for commit 221d423. Configure here.