Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion 4 src/utils/api.mts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ import constants, {
HTTP_STATUS_UNAUTHORIZED,
} from '../constants.mts'
import { getRequirements, getRequirementsKey } from './requirements.mts'
import { getDefaultApiToken, getExtraCaCerts } from './sdk.mts'
import { getCliUserAgent, getDefaultApiToken, getExtraCaCerts } from './sdk.mts'

Comment on lines 39 to 43
import type { CResult } from '../types.mts'
import type { Spinner } from '@socketsecurity/registry/lib/spinner'
Expand Down Expand Up @@ -437,6 +437,7 @@ async function queryApi(path: string, apiToken: string) {
method: 'GET',
headers: {
Authorization: `Basic ${btoa(`${apiToken}:`)}`,
'User-Agent': getCliUserAgent(),
},
})
return result
Expand Down Expand Up @@ -622,6 +623,7 @@ export async function sendApiRequest<T>(
headers: {
Authorization: `Basic ${btoa(`${apiToken}:`)}`,
'Content-Type': 'application/json',
'User-Agent': getCliUserAgent(),
},
...(body ? { body: JSON.stringify(body) } : {}),
}
Expand Down
4 changes: 3 additions & 1 deletion 4 src/utils/dlx.mts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import constants, {
} from '../constants.mts'
import { getErrorCause } from './errors.mts'
import { findUp } from './fs.mts'
import { getDefaultApiToken, getDefaultProxyUrl } from './sdk.mts'
import { getCliUserAgent, getDefaultApiToken, getDefaultProxyUrl } from './sdk.mts'
import { isYarnBerry } from './yarn-version.mts'

import type { ShadowBinOptions, ShadowBinResult } from '../shadow/npm-base.mts'
Expand Down Expand Up @@ -207,6 +207,8 @@ export async function spawnCoanaDlx(

const mixinsEnv: Record<string, string> = {
SOCKET_CLI_VERSION: constants.ENV.INLINED_SOCKET_CLI_VERSION,
// Pass the CLI's full user agent so coana can append it to its own UA.
SOCKET_CALLER_USER_AGENT: getCliUserAgent(),
}
Comment on lines 208 to 212
const defaultApiToken = getDefaultApiToken()
if (defaultApiToken) {
Expand Down
20 changes: 20 additions & 0 deletions 20 src/utils/sdk.mts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,26 @@ import { trackCliEvent } from './telemetry/integration.mts'
import type { CResult } from '../types.mts'
import type { RequestInfo, ResponseInfo } from '@socketsecurity/sdk'

// Lazy-evaluated full CLI user agent for direct (non-SDK) API calls.
// Includes the CLI product token, Node.js version, and OS platform/arch.
// e.g. "socket/1.1.96 node/v22.0.0 linux/arm64"
let _cliUserAgent: string | undefined
export function getCliUserAgent(): string {
if (!_cliUserAgent) {
const name = constants.ENV.INLINED_SOCKET_CLI_NAME.replace('@', '').replace(
'/',
'-',
)
const version = constants.ENV.INLINED_SOCKET_CLI_VERSION
_cliUserAgent = [
`${name}/${version}`,
`node/${process.version}`,
`${process.platform}/${process.arch}`,
].join(' ')
}
return _cliUserAgent
}
Comment on lines +53 to +71

const TOKEN_PREFIX = 'sktsec_'
const TOKEN_PREFIX_LENGTH = TOKEN_PREFIX.length
const TOKEN_VISIBLE_LENGTH = 5
Expand Down
Loading
Morty Proxy This is a proxified and sanitized view of the page, visit original site.