@socketsecurity/cli-with-sentry 1.18.1 → 1.18.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +8 -0
- package/README.md +5 -5
- package/dist/.config/tsconfig.dts.tsbuildinfo +1 -1
- package/dist/cli.js +810 -484
- package/dist/cli.js.map +1 -1
- package/dist/constants.js +5 -5
- package/dist/constants.js.map +1 -1
- package/dist/types/commands/ci/detect-ci-pull-request-context.d.mts +7 -0
- package/dist/types/commands/ci/handle-ci.d.mts +0 -7
- package/dist/types/commands/ci/publish-pr-comments.d.mts +12 -0
- package/dist/types/commands/ci/select-baseline-scan.d.mts +10 -0
- package/dist/types/commands/manifest/run-manifest-facts.d.mts +1 -0
- package/dist/types/commands/scan/fetch-diff-scan.d.mts +17 -2
- package/dist/types/commands/scan/fetch-list-scans.d.mts +1 -0
- package/dist/types/commands/scan/handle-create-new-scan.d.mts +2 -0
- package/dist/types/commands/scan/handle-diff-scan.d.mts +9 -1
- package/dist/types/commands/scan/output-create-new-scan.d.mts +1 -0
- package/dist/types/commands/scan/output-diff-scan.d.mts +3 -4
- package/dist/types/constants.d.mts +1 -1
- package/dist/types/sea/version.d.mts +1 -1
- package/dist/types/utils/ci-exit-code.d.mts +11 -0
- package/dist/types/utils/coana.d.mts +1 -0
- package/dist/types/utils/github.d.mts +7 -0
- package/dist/utils.js +365 -286
- package/dist/utils.js.map +1 -1
- package/dist/vendor.js +17555 -19029
- package/package.json +45 -42
- package/requirements.json +2 -2
package/dist/utils.js
CHANGED
|
@@ -5425,59 +5425,6 @@ async function getDefaultOrgSlug(silence) {
|
|
|
5425
5425
|
};
|
|
5426
5426
|
}
|
|
5427
5427
|
|
|
5428
|
-
/**
|
|
5429
|
-
* Sanitizes a name to comply with repository naming constraints.
|
|
5430
|
-
* Constraints: 100 or less A-Za-z0-9 characters only with non-repeating,
|
|
5431
|
-
* non-leading or trailing ., _ or - only.
|
|
5432
|
-
*
|
|
5433
|
-
* @param name - The name to sanitize
|
|
5434
|
-
* @returns Sanitized name that complies with repository naming rules, or empty string if no valid characters
|
|
5435
|
-
*/
|
|
5436
|
-
function sanitizeName(name) {
|
|
5437
|
-
if (!name) {
|
|
5438
|
-
return '';
|
|
5439
|
-
}
|
|
5440
|
-
|
|
5441
|
-
// Replace sequences of illegal characters with underscores.
|
|
5442
|
-
const sanitized = name
|
|
5443
|
-
// Replace any sequence of non-alphanumeric characters (except ., _, -) with underscore.
|
|
5444
|
-
.replace(/[^A-Za-z0-9._-]+/g, '_')
|
|
5445
|
-
// Replace sequences of multiple allowed special chars with single underscore.
|
|
5446
|
-
.replace(/[._-]{2,}/g, '_')
|
|
5447
|
-
// Remove leading special characters.
|
|
5448
|
-
.replace(/^[._-]+/, '')
|
|
5449
|
-
// Remove trailing special characters.
|
|
5450
|
-
.replace(/[._-]+$/, '')
|
|
5451
|
-
// Truncate to 100 characters max.
|
|
5452
|
-
.slice(0, 100);
|
|
5453
|
-
return sanitized;
|
|
5454
|
-
}
|
|
5455
|
-
|
|
5456
|
-
/**
|
|
5457
|
-
* Extracts and sanitizes a repository name.
|
|
5458
|
-
*
|
|
5459
|
-
* @param name - The repository name to extract and sanitize
|
|
5460
|
-
* @returns Sanitized repository name, or default repository name if empty
|
|
5461
|
-
*/
|
|
5462
|
-
function extractName(name) {
|
|
5463
|
-
const sanitized = sanitizeName(name);
|
|
5464
|
-
return sanitized || constants.default.SOCKET_DEFAULT_REPOSITORY;
|
|
5465
|
-
}
|
|
5466
|
-
|
|
5467
|
-
/**
|
|
5468
|
-
* Extracts and sanitizes a repository owner name.
|
|
5469
|
-
*
|
|
5470
|
-
* @param owner - The repository owner name to extract and sanitize
|
|
5471
|
-
* @returns Sanitized repository owner name, or undefined if input is empty
|
|
5472
|
-
*/
|
|
5473
|
-
function extractOwner(owner) {
|
|
5474
|
-
if (!owner) {
|
|
5475
|
-
return undefined;
|
|
5476
|
-
}
|
|
5477
|
-
const sanitized = sanitizeName(owner);
|
|
5478
|
-
return sanitized || undefined;
|
|
5479
|
-
}
|
|
5480
|
-
|
|
5481
5428
|
const ansiRegExp =
|
|
5482
5429
|
// eslint-disable-next-line no-control-regex -- The expression removes ANSI control codes.
|
|
5483
5430
|
/(?:\u001B\][\s\S]*?(?:\u0007|\u001B\\|\u009C)|[\u001B\u009B][[\]()#;?]*(?:\d{1,4}(?:[;:]\d{0,4})*)?[\dA-PR-TZcf-nq-uy=><~])/g;
|
|
@@ -5597,21 +5544,366 @@ function spawn(cmd, args, options, extra) {
|
|
|
5597
5544
|
}
|
|
5598
5545
|
return spawnPromise;
|
|
5599
5546
|
}
|
|
5600
|
-
const abortController = new AbortController();
|
|
5601
|
-
const abortSignal = abortController.signal;
|
|
5602
|
-
for (const signal of ['SIGHUP', 'SIGINT', 'SIGTERM']) {
|
|
5603
|
-
const handler = () => {
|
|
5604
|
-
abortController.abort();
|
|
5605
|
-
process.removeListener(signal, handler);
|
|
5606
|
-
process.kill(process.pid, signal);
|
|
5607
|
-
};
|
|
5608
|
-
try {
|
|
5609
|
-
process.once(signal, handler);
|
|
5610
|
-
} catch {
|
|
5611
|
-
// Some signals are unavailable on Windows.
|
|
5547
|
+
const abortController = new AbortController();
|
|
5548
|
+
const abortSignal = abortController.signal;
|
|
5549
|
+
for (const signal of ['SIGHUP', 'SIGINT', 'SIGTERM']) {
|
|
5550
|
+
const handler = () => {
|
|
5551
|
+
abortController.abort();
|
|
5552
|
+
process.removeListener(signal, handler);
|
|
5553
|
+
process.kill(process.pid, signal);
|
|
5554
|
+
};
|
|
5555
|
+
try {
|
|
5556
|
+
process.once(signal, handler);
|
|
5557
|
+
} catch {
|
|
5558
|
+
// Some signals are unavailable on Windows.
|
|
5559
|
+
}
|
|
5560
|
+
}
|
|
5561
|
+
process.once('exit', () => abortController.abort());
|
|
5562
|
+
|
|
5563
|
+
/**
|
|
5564
|
+
* GitHub utilities for Socket CLI.
|
|
5565
|
+
* Provides GitHub API integration for repository operations and GHSA vulnerability data.
|
|
5566
|
+
*
|
|
5567
|
+
* Authentication:
|
|
5568
|
+
* - getGitHubToken: Retrieve GitHub token from env/git config
|
|
5569
|
+
* - getOctokit: Get authenticated Octokit instance
|
|
5570
|
+
* - getOctokitGraphql: Get authenticated GraphQL client
|
|
5571
|
+
*
|
|
5572
|
+
* Caching:
|
|
5573
|
+
* - 5-minute TTL for API responses
|
|
5574
|
+
* - Automatic cache invalidation
|
|
5575
|
+
* - Persistent cache in node_modules/.cache
|
|
5576
|
+
*
|
|
5577
|
+
* GHSA Operations:
|
|
5578
|
+
* - cacheFetch: Cache API responses with TTL
|
|
5579
|
+
* - fetchGhsaDetails: Fetch GitHub Security Advisory details
|
|
5580
|
+
* - getGhsaUrl: Generate GHSA advisory URL
|
|
5581
|
+
* - readCache/writeCache: Persistent cache operations
|
|
5582
|
+
*
|
|
5583
|
+
* Repository Operations:
|
|
5584
|
+
* - GraphQL queries for complex operations
|
|
5585
|
+
* - Integration with Octokit REST API
|
|
5586
|
+
* - Support for GitHub Actions environment variables
|
|
5587
|
+
*/
|
|
5588
|
+
|
|
5589
|
+
async function readCache(key,
|
|
5590
|
+
// 5 minute in milliseconds time to live (TTL).
|
|
5591
|
+
ttlMs = 5 * 60 * 1000) {
|
|
5592
|
+
const cacheJsonPath = path.join(constants.default.githubCachePath, `${key}.json`);
|
|
5593
|
+
const stat = safeStatsSync(cacheJsonPath);
|
|
5594
|
+
if (stat) {
|
|
5595
|
+
const isExpired = Date.now() - Number(stat.mtimeMs) > ttlMs;
|
|
5596
|
+
if (!isExpired) {
|
|
5597
|
+
return (await readJson(cacheJsonPath)) ?? undefined;
|
|
5598
|
+
}
|
|
5599
|
+
}
|
|
5600
|
+
return undefined;
|
|
5601
|
+
}
|
|
5602
|
+
async function writeCache(key, data) {
|
|
5603
|
+
const {
|
|
5604
|
+
githubCachePath
|
|
5605
|
+
} = constants.default;
|
|
5606
|
+
const cacheJsonPath = path.join(githubCachePath, `${key}.json`);
|
|
5607
|
+
if (!u.existsSync(githubCachePath)) {
|
|
5608
|
+
await u.promises.mkdir(githubCachePath, {
|
|
5609
|
+
recursive: true
|
|
5610
|
+
});
|
|
5611
|
+
}
|
|
5612
|
+
await writeJson(cacheJsonPath, data);
|
|
5613
|
+
}
|
|
5614
|
+
async function cacheFetch(key, fetcher, ttlMs) {
|
|
5615
|
+
// Optionally disable cache.
|
|
5616
|
+
if (constants.default.ENV.DISABLE_GITHUB_CACHE) {
|
|
5617
|
+
return await fetcher();
|
|
5618
|
+
}
|
|
5619
|
+
let data = await readCache(key, ttlMs);
|
|
5620
|
+
if (!data) {
|
|
5621
|
+
data = await fetcher();
|
|
5622
|
+
await writeCache(key, data);
|
|
5623
|
+
}
|
|
5624
|
+
return data;
|
|
5625
|
+
}
|
|
5626
|
+
async function fetchGhsaDetails(ids) {
|
|
5627
|
+
const results = new Map();
|
|
5628
|
+
if (!ids.length) {
|
|
5629
|
+
return results;
|
|
5630
|
+
}
|
|
5631
|
+
const octokitGraphql = getOctokitGraphql();
|
|
5632
|
+
try {
|
|
5633
|
+
const gqlCacheKey = `${ids.join('-')}-graphql-snapshot`;
|
|
5634
|
+
const aliases = ids.map((id, index) => `advisory${index}: securityAdvisory(ghsaId: "${id}") {
|
|
5635
|
+
ghsaId
|
|
5636
|
+
summary
|
|
5637
|
+
severity
|
|
5638
|
+
publishedAt
|
|
5639
|
+
withdrawnAt
|
|
5640
|
+
vulnerabilities(first: 10) {
|
|
5641
|
+
nodes {
|
|
5642
|
+
package {
|
|
5643
|
+
ecosystem
|
|
5644
|
+
name
|
|
5645
|
+
}
|
|
5646
|
+
vulnerableVersionRange
|
|
5647
|
+
}
|
|
5648
|
+
}
|
|
5649
|
+
}`).join('\n');
|
|
5650
|
+
const gqlResp = await cacheFetch(gqlCacheKey, () => octokitGraphql(`
|
|
5651
|
+
query {
|
|
5652
|
+
${aliases}
|
|
5653
|
+
}
|
|
5654
|
+
`));
|
|
5655
|
+
for (let i = 0, {
|
|
5656
|
+
length
|
|
5657
|
+
} = ids; i < length; i += 1) {
|
|
5658
|
+
const id = ids[i];
|
|
5659
|
+
const advisoryKey = `advisory${i}`;
|
|
5660
|
+
const advisory = gqlResp?.[advisoryKey];
|
|
5661
|
+
if (advisory && advisory.ghsaId) {
|
|
5662
|
+
results.set(id, advisory);
|
|
5663
|
+
} else {
|
|
5664
|
+
debugFn('notice', `miss: no advisory found for ${id}`);
|
|
5665
|
+
}
|
|
5666
|
+
}
|
|
5667
|
+
} catch (e) {
|
|
5668
|
+
debugFn('error', formatErrorWithDetail('Failed to fetch GHSA details', e));
|
|
5669
|
+
debugDir('error', e);
|
|
5670
|
+
}
|
|
5671
|
+
return results;
|
|
5672
|
+
}
|
|
5673
|
+
let _octokit;
|
|
5674
|
+
function getOctokit() {
|
|
5675
|
+
if (_octokit === undefined) {
|
|
5676
|
+
const {
|
|
5677
|
+
SOCKET_CLI_GITHUB_TOKEN
|
|
5678
|
+
} = constants.default.ENV;
|
|
5679
|
+
if (!SOCKET_CLI_GITHUB_TOKEN) {
|
|
5680
|
+
debugFn('notice', 'miss: SOCKET_CLI_GITHUB_TOKEN env var');
|
|
5681
|
+
}
|
|
5682
|
+
const octokitOptions = {
|
|
5683
|
+
auth: SOCKET_CLI_GITHUB_TOKEN,
|
|
5684
|
+
baseUrl: constants.default.ENV.GITHUB_API_URL
|
|
5685
|
+
};
|
|
5686
|
+
debugDir('inspect', {
|
|
5687
|
+
baseUrl: octokitOptions.baseUrl
|
|
5688
|
+
});
|
|
5689
|
+
_octokit = new vendor.Octokit(octokitOptions);
|
|
5690
|
+
}
|
|
5691
|
+
return _octokit;
|
|
5692
|
+
}
|
|
5693
|
+
let _octokitGraphql;
|
|
5694
|
+
function getOctokitGraphql() {
|
|
5695
|
+
if (!_octokitGraphql) {
|
|
5696
|
+
const {
|
|
5697
|
+
SOCKET_CLI_GITHUB_TOKEN
|
|
5698
|
+
} = constants.default.ENV;
|
|
5699
|
+
if (!SOCKET_CLI_GITHUB_TOKEN) {
|
|
5700
|
+
debugFn('notice', 'miss: SOCKET_CLI_GITHUB_TOKEN env var');
|
|
5701
|
+
}
|
|
5702
|
+
_octokitGraphql = vendor.graphql2.defaults({
|
|
5703
|
+
headers: {
|
|
5704
|
+
authorization: `token ${SOCKET_CLI_GITHUB_TOKEN}`
|
|
5705
|
+
}
|
|
5706
|
+
});
|
|
5707
|
+
}
|
|
5708
|
+
return _octokitGraphql;
|
|
5709
|
+
}
|
|
5710
|
+
async function enablePrAutoMerge({
|
|
5711
|
+
node_id: prId
|
|
5712
|
+
}) {
|
|
5713
|
+
const octokitGraphql = getOctokitGraphql();
|
|
5714
|
+
try {
|
|
5715
|
+
const gqlResp = await octokitGraphql(`
|
|
5716
|
+
mutation EnableAutoMerge($pullRequestId: ID!) {
|
|
5717
|
+
enablePullRequestAutoMerge(input: {
|
|
5718
|
+
pullRequestId: $pullRequestId,
|
|
5719
|
+
mergeMethod: SQUASH
|
|
5720
|
+
}) {
|
|
5721
|
+
pullRequest {
|
|
5722
|
+
number
|
|
5723
|
+
}
|
|
5724
|
+
}
|
|
5725
|
+
}`, {
|
|
5726
|
+
pullRequestId: prId
|
|
5727
|
+
});
|
|
5728
|
+
const respPrNumber = gqlResp?.enablePullRequestAutoMerge?.pullRequest?.number;
|
|
5729
|
+
if (respPrNumber) {
|
|
5730
|
+
return {
|
|
5731
|
+
enabled: true
|
|
5732
|
+
};
|
|
5733
|
+
}
|
|
5734
|
+
} catch (e) {
|
|
5735
|
+
if (e instanceof vendor.GraphqlResponseError && Array.isArray(e.errors) && e.errors.length) {
|
|
5736
|
+
const details = e.errors.map(({
|
|
5737
|
+
message: m
|
|
5738
|
+
}) => m.trim());
|
|
5739
|
+
return {
|
|
5740
|
+
enabled: false,
|
|
5741
|
+
details
|
|
5742
|
+
};
|
|
5743
|
+
}
|
|
5744
|
+
}
|
|
5745
|
+
return {
|
|
5746
|
+
enabled: false
|
|
5747
|
+
};
|
|
5748
|
+
}
|
|
5749
|
+
async function upsertPullRequestComment({
|
|
5750
|
+
body,
|
|
5751
|
+
marker,
|
|
5752
|
+
owner,
|
|
5753
|
+
pullRequest,
|
|
5754
|
+
repo
|
|
5755
|
+
}) {
|
|
5756
|
+
const octokit = getOctokit();
|
|
5757
|
+
const comments = await octokit.paginate(octokit.issues.listComments, {
|
|
5758
|
+
issue_number: pullRequest,
|
|
5759
|
+
owner,
|
|
5760
|
+
per_page: 100,
|
|
5761
|
+
repo
|
|
5762
|
+
});
|
|
5763
|
+
const existing = comments.find(comment => comment.body?.includes(marker));
|
|
5764
|
+
if (existing) {
|
|
5765
|
+
await octokit.issues.updateComment({
|
|
5766
|
+
body,
|
|
5767
|
+
comment_id: existing.id,
|
|
5768
|
+
owner,
|
|
5769
|
+
repo
|
|
5770
|
+
});
|
|
5771
|
+
return;
|
|
5772
|
+
}
|
|
5773
|
+
await octokit.issues.createComment({
|
|
5774
|
+
body,
|
|
5775
|
+
issue_number: pullRequest,
|
|
5776
|
+
owner,
|
|
5777
|
+
repo
|
|
5778
|
+
});
|
|
5779
|
+
}
|
|
5780
|
+
async function setGitRemoteGithubRepoUrl(owner, repo, token, cwd = process.cwd()) {
|
|
5781
|
+
const {
|
|
5782
|
+
GITHUB_SERVER_URL
|
|
5783
|
+
} = constants.default.ENV;
|
|
5784
|
+
const urlObj = parseUrl(GITHUB_SERVER_URL);
|
|
5785
|
+
const host = urlObj?.host;
|
|
5786
|
+
if (!host) {
|
|
5787
|
+
debugFn('error', 'invalid: GITHUB_SERVER_URL env var');
|
|
5788
|
+
debugDir('inspect', {
|
|
5789
|
+
GITHUB_SERVER_URL
|
|
5790
|
+
});
|
|
5791
|
+
return false;
|
|
5792
|
+
}
|
|
5793
|
+
const url = `https://x-access-token:${token}@${host}/${owner}/${repo}`;
|
|
5794
|
+
const stdioIgnoreOptions = {
|
|
5795
|
+
cwd,
|
|
5796
|
+
stdio: isDebug('stdio') ? 'inherit' : 'ignore'
|
|
5797
|
+
};
|
|
5798
|
+
const quotedCmd = `\`git remote set-url origin ${url}\``;
|
|
5799
|
+
debugFn('stdio', `spawn: ${quotedCmd}`);
|
|
5800
|
+
try {
|
|
5801
|
+
await spawn('git', ['remote', 'set-url', 'origin', url], stdioIgnoreOptions);
|
|
5802
|
+
return true;
|
|
5803
|
+
} catch (e) {
|
|
5804
|
+
debugFn('error', `Git command failed: ${quotedCmd}`);
|
|
5805
|
+
debugDir('inspect', {
|
|
5806
|
+
cmd: quotedCmd
|
|
5807
|
+
});
|
|
5808
|
+
debugDir('error', e);
|
|
5809
|
+
}
|
|
5810
|
+
return false;
|
|
5811
|
+
}
|
|
5812
|
+
|
|
5813
|
+
const ciExitCodeState = {};
|
|
5814
|
+
function setCiExitCodePolicy(policy) {
|
|
5815
|
+
ciExitCodeState.policy = policy;
|
|
5816
|
+
}
|
|
5817
|
+
function hasCiExitCodePolicy() {
|
|
5818
|
+
return ciExitCodeState.policy !== undefined;
|
|
5819
|
+
}
|
|
5820
|
+
function setCiExitCode(kind, fallback = 1) {
|
|
5821
|
+
const {
|
|
5822
|
+
policy
|
|
5823
|
+
} = ciExitCodeState;
|
|
5824
|
+
if (!policy) {
|
|
5825
|
+
process.exitCode = fallback;
|
|
5826
|
+
return;
|
|
5827
|
+
}
|
|
5828
|
+
if (kind !== 'usage' && constants.default.abortSignal.aborted) {
|
|
5829
|
+
kind = 'interrupted';
|
|
5830
|
+
}
|
|
5831
|
+
if (kind === 'usage') {
|
|
5832
|
+
process.exitCode = 2;
|
|
5833
|
+
return;
|
|
5834
|
+
}
|
|
5835
|
+
if (policy.disableBlocking) {
|
|
5836
|
+
process.exitCode = 0;
|
|
5837
|
+
return;
|
|
5838
|
+
}
|
|
5839
|
+
switch (kind) {
|
|
5840
|
+
case 'api':
|
|
5841
|
+
process.exitCode = policy.exitCodeOnApiError ?? 3;
|
|
5842
|
+
return;
|
|
5843
|
+
case 'blocking':
|
|
5844
|
+
process.exitCode = 1;
|
|
5845
|
+
return;
|
|
5846
|
+
case 'infrastructure':
|
|
5847
|
+
process.exitCode = 3;
|
|
5848
|
+
return;
|
|
5849
|
+
case 'interrupted':
|
|
5850
|
+
process.exitCode = 130;
|
|
5851
|
+
return;
|
|
5852
|
+
}
|
|
5853
|
+
}
|
|
5854
|
+
|
|
5855
|
+
/**
|
|
5856
|
+
* Sanitizes a name to comply with repository naming constraints.
|
|
5857
|
+
* Constraints: 100 or less A-Za-z0-9 characters only with non-repeating,
|
|
5858
|
+
* non-leading or trailing ., _ or - only.
|
|
5859
|
+
*
|
|
5860
|
+
* @param name - The name to sanitize
|
|
5861
|
+
* @returns Sanitized name that complies with repository naming rules, or empty string if no valid characters
|
|
5862
|
+
*/
|
|
5863
|
+
function sanitizeName(name) {
|
|
5864
|
+
if (!name) {
|
|
5865
|
+
return '';
|
|
5866
|
+
}
|
|
5867
|
+
|
|
5868
|
+
// Replace sequences of illegal characters with underscores.
|
|
5869
|
+
const sanitized = name
|
|
5870
|
+
// Replace any sequence of non-alphanumeric characters (except ., _, -) with underscore.
|
|
5871
|
+
.replace(/[^A-Za-z0-9._-]+/g, '_')
|
|
5872
|
+
// Replace sequences of multiple allowed special chars with single underscore.
|
|
5873
|
+
.replace(/[._-]{2,}/g, '_')
|
|
5874
|
+
// Remove leading special characters.
|
|
5875
|
+
.replace(/^[._-]+/, '')
|
|
5876
|
+
// Remove trailing special characters.
|
|
5877
|
+
.replace(/[._-]+$/, '')
|
|
5878
|
+
// Truncate to 100 characters max.
|
|
5879
|
+
.slice(0, 100);
|
|
5880
|
+
return sanitized;
|
|
5881
|
+
}
|
|
5882
|
+
|
|
5883
|
+
/**
|
|
5884
|
+
* Extracts and sanitizes a repository name.
|
|
5885
|
+
*
|
|
5886
|
+
* @param name - The repository name to extract and sanitize
|
|
5887
|
+
* @returns Sanitized repository name, or default repository name if empty
|
|
5888
|
+
*/
|
|
5889
|
+
function extractName(name) {
|
|
5890
|
+
const sanitized = sanitizeName(name);
|
|
5891
|
+
return sanitized || constants.default.SOCKET_DEFAULT_REPOSITORY;
|
|
5892
|
+
}
|
|
5893
|
+
|
|
5894
|
+
/**
|
|
5895
|
+
* Extracts and sanitizes a repository owner name.
|
|
5896
|
+
*
|
|
5897
|
+
* @param owner - The repository owner name to extract and sanitize
|
|
5898
|
+
* @returns Sanitized repository owner name, or undefined if input is empty
|
|
5899
|
+
*/
|
|
5900
|
+
function extractOwner(owner) {
|
|
5901
|
+
if (!owner) {
|
|
5902
|
+
return undefined;
|
|
5612
5903
|
}
|
|
5904
|
+
const sanitized = sanitizeName(owner);
|
|
5905
|
+
return sanitized || undefined;
|
|
5613
5906
|
}
|
|
5614
|
-
process.once('exit', () => abortController.abort());
|
|
5615
5907
|
|
|
5616
5908
|
/**
|
|
5617
5909
|
* Git utilities for Socket CLI.
|
|
@@ -9992,6 +10284,7 @@ async function spawnCoana(args, orgSlug, options) {
|
|
|
9992
10284
|
const {
|
|
9993
10285
|
DOT_SOCKET_DOT_FACTS_JSON
|
|
9994
10286
|
} = constants.default;
|
|
10287
|
+
const DISABLE_DEPENDENCY_DOWNLOADS_FLAG = '--disable-dependency-downloads';
|
|
9995
10288
|
/**
|
|
9996
10289
|
* For each `.socket.facts.json` in `scanPaths`, stream-brotli-compress a
|
|
9997
10290
|
* sibling `.socket.facts.json.br` next to the original file and swap its
|
|
@@ -10879,225 +11172,6 @@ async function getPackageFilesForScan(inputPaths, supportedFiles, options) {
|
|
|
10879
11172
|
});
|
|
10880
11173
|
}
|
|
10881
11174
|
|
|
10882
|
-
/**
|
|
10883
|
-
* GitHub utilities for Socket CLI.
|
|
10884
|
-
* Provides GitHub API integration for repository operations and GHSA vulnerability data.
|
|
10885
|
-
*
|
|
10886
|
-
* Authentication:
|
|
10887
|
-
* - getGitHubToken: Retrieve GitHub token from env/git config
|
|
10888
|
-
* - getOctokit: Get authenticated Octokit instance
|
|
10889
|
-
* - getOctokitGraphql: Get authenticated GraphQL client
|
|
10890
|
-
*
|
|
10891
|
-
* Caching:
|
|
10892
|
-
* - 5-minute TTL for API responses
|
|
10893
|
-
* - Automatic cache invalidation
|
|
10894
|
-
* - Persistent cache in node_modules/.cache
|
|
10895
|
-
*
|
|
10896
|
-
* GHSA Operations:
|
|
10897
|
-
* - cacheFetch: Cache API responses with TTL
|
|
10898
|
-
* - fetchGhsaDetails: Fetch GitHub Security Advisory details
|
|
10899
|
-
* - getGhsaUrl: Generate GHSA advisory URL
|
|
10900
|
-
* - readCache/writeCache: Persistent cache operations
|
|
10901
|
-
*
|
|
10902
|
-
* Repository Operations:
|
|
10903
|
-
* - GraphQL queries for complex operations
|
|
10904
|
-
* - Integration with Octokit REST API
|
|
10905
|
-
* - Support for GitHub Actions environment variables
|
|
10906
|
-
*/
|
|
10907
|
-
|
|
10908
|
-
async function readCache(key,
|
|
10909
|
-
// 5 minute in milliseconds time to live (TTL).
|
|
10910
|
-
ttlMs = 5 * 60 * 1000) {
|
|
10911
|
-
const cacheJsonPath = path.join(constants.default.githubCachePath, `${key}.json`);
|
|
10912
|
-
const stat = safeStatsSync(cacheJsonPath);
|
|
10913
|
-
if (stat) {
|
|
10914
|
-
const isExpired = Date.now() - Number(stat.mtimeMs) > ttlMs;
|
|
10915
|
-
if (!isExpired) {
|
|
10916
|
-
return (await readJson(cacheJsonPath)) ?? undefined;
|
|
10917
|
-
}
|
|
10918
|
-
}
|
|
10919
|
-
return undefined;
|
|
10920
|
-
}
|
|
10921
|
-
async function writeCache(key, data) {
|
|
10922
|
-
const {
|
|
10923
|
-
githubCachePath
|
|
10924
|
-
} = constants.default;
|
|
10925
|
-
const cacheJsonPath = path.join(githubCachePath, `${key}.json`);
|
|
10926
|
-
if (!u.existsSync(githubCachePath)) {
|
|
10927
|
-
await u.promises.mkdir(githubCachePath, {
|
|
10928
|
-
recursive: true
|
|
10929
|
-
});
|
|
10930
|
-
}
|
|
10931
|
-
await writeJson(cacheJsonPath, data);
|
|
10932
|
-
}
|
|
10933
|
-
async function cacheFetch(key, fetcher, ttlMs) {
|
|
10934
|
-
// Optionally disable cache.
|
|
10935
|
-
if (constants.default.ENV.DISABLE_GITHUB_CACHE) {
|
|
10936
|
-
return await fetcher();
|
|
10937
|
-
}
|
|
10938
|
-
let data = await readCache(key, ttlMs);
|
|
10939
|
-
if (!data) {
|
|
10940
|
-
data = await fetcher();
|
|
10941
|
-
await writeCache(key, data);
|
|
10942
|
-
}
|
|
10943
|
-
return data;
|
|
10944
|
-
}
|
|
10945
|
-
async function fetchGhsaDetails(ids) {
|
|
10946
|
-
const results = new Map();
|
|
10947
|
-
if (!ids.length) {
|
|
10948
|
-
return results;
|
|
10949
|
-
}
|
|
10950
|
-
const octokitGraphql = getOctokitGraphql();
|
|
10951
|
-
try {
|
|
10952
|
-
const gqlCacheKey = `${ids.join('-')}-graphql-snapshot`;
|
|
10953
|
-
const aliases = ids.map((id, index) => `advisory${index}: securityAdvisory(ghsaId: "${id}") {
|
|
10954
|
-
ghsaId
|
|
10955
|
-
summary
|
|
10956
|
-
severity
|
|
10957
|
-
publishedAt
|
|
10958
|
-
withdrawnAt
|
|
10959
|
-
vulnerabilities(first: 10) {
|
|
10960
|
-
nodes {
|
|
10961
|
-
package {
|
|
10962
|
-
ecosystem
|
|
10963
|
-
name
|
|
10964
|
-
}
|
|
10965
|
-
vulnerableVersionRange
|
|
10966
|
-
}
|
|
10967
|
-
}
|
|
10968
|
-
}`).join('\n');
|
|
10969
|
-
const gqlResp = await cacheFetch(gqlCacheKey, () => octokitGraphql(`
|
|
10970
|
-
query {
|
|
10971
|
-
${aliases}
|
|
10972
|
-
}
|
|
10973
|
-
`));
|
|
10974
|
-
for (let i = 0, {
|
|
10975
|
-
length
|
|
10976
|
-
} = ids; i < length; i += 1) {
|
|
10977
|
-
const id = ids[i];
|
|
10978
|
-
const advisoryKey = `advisory${i}`;
|
|
10979
|
-
const advisory = gqlResp?.[advisoryKey];
|
|
10980
|
-
if (advisory && advisory.ghsaId) {
|
|
10981
|
-
results.set(id, advisory);
|
|
10982
|
-
} else {
|
|
10983
|
-
debugFn('notice', `miss: no advisory found for ${id}`);
|
|
10984
|
-
}
|
|
10985
|
-
}
|
|
10986
|
-
} catch (e) {
|
|
10987
|
-
debugFn('error', formatErrorWithDetail('Failed to fetch GHSA details', e));
|
|
10988
|
-
debugDir('error', e);
|
|
10989
|
-
}
|
|
10990
|
-
return results;
|
|
10991
|
-
}
|
|
10992
|
-
let _octokit;
|
|
10993
|
-
function getOctokit() {
|
|
10994
|
-
if (_octokit === undefined) {
|
|
10995
|
-
const {
|
|
10996
|
-
SOCKET_CLI_GITHUB_TOKEN
|
|
10997
|
-
} = constants.default.ENV;
|
|
10998
|
-
if (!SOCKET_CLI_GITHUB_TOKEN) {
|
|
10999
|
-
debugFn('notice', 'miss: SOCKET_CLI_GITHUB_TOKEN env var');
|
|
11000
|
-
}
|
|
11001
|
-
const octokitOptions = {
|
|
11002
|
-
auth: SOCKET_CLI_GITHUB_TOKEN,
|
|
11003
|
-
baseUrl: constants.default.ENV.GITHUB_API_URL
|
|
11004
|
-
};
|
|
11005
|
-
debugDir('inspect', {
|
|
11006
|
-
octokitOptions
|
|
11007
|
-
});
|
|
11008
|
-
_octokit = new vendor.Octokit(octokitOptions);
|
|
11009
|
-
}
|
|
11010
|
-
return _octokit;
|
|
11011
|
-
}
|
|
11012
|
-
let _octokitGraphql;
|
|
11013
|
-
function getOctokitGraphql() {
|
|
11014
|
-
if (!_octokitGraphql) {
|
|
11015
|
-
const {
|
|
11016
|
-
SOCKET_CLI_GITHUB_TOKEN
|
|
11017
|
-
} = constants.default.ENV;
|
|
11018
|
-
if (!SOCKET_CLI_GITHUB_TOKEN) {
|
|
11019
|
-
debugFn('notice', 'miss: SOCKET_CLI_GITHUB_TOKEN env var');
|
|
11020
|
-
}
|
|
11021
|
-
_octokitGraphql = vendor.graphql2.defaults({
|
|
11022
|
-
headers: {
|
|
11023
|
-
authorization: `token ${SOCKET_CLI_GITHUB_TOKEN}`
|
|
11024
|
-
}
|
|
11025
|
-
});
|
|
11026
|
-
}
|
|
11027
|
-
return _octokitGraphql;
|
|
11028
|
-
}
|
|
11029
|
-
async function enablePrAutoMerge({
|
|
11030
|
-
node_id: prId
|
|
11031
|
-
}) {
|
|
11032
|
-
const octokitGraphql = getOctokitGraphql();
|
|
11033
|
-
try {
|
|
11034
|
-
const gqlResp = await octokitGraphql(`
|
|
11035
|
-
mutation EnableAutoMerge($pullRequestId: ID!) {
|
|
11036
|
-
enablePullRequestAutoMerge(input: {
|
|
11037
|
-
pullRequestId: $pullRequestId,
|
|
11038
|
-
mergeMethod: SQUASH
|
|
11039
|
-
}) {
|
|
11040
|
-
pullRequest {
|
|
11041
|
-
number
|
|
11042
|
-
}
|
|
11043
|
-
}
|
|
11044
|
-
}`, {
|
|
11045
|
-
pullRequestId: prId
|
|
11046
|
-
});
|
|
11047
|
-
const respPrNumber = gqlResp?.enablePullRequestAutoMerge?.pullRequest?.number;
|
|
11048
|
-
if (respPrNumber) {
|
|
11049
|
-
return {
|
|
11050
|
-
enabled: true
|
|
11051
|
-
};
|
|
11052
|
-
}
|
|
11053
|
-
} catch (e) {
|
|
11054
|
-
if (e instanceof vendor.GraphqlResponseError && Array.isArray(e.errors) && e.errors.length) {
|
|
11055
|
-
const details = e.errors.map(({
|
|
11056
|
-
message: m
|
|
11057
|
-
}) => m.trim());
|
|
11058
|
-
return {
|
|
11059
|
-
enabled: false,
|
|
11060
|
-
details
|
|
11061
|
-
};
|
|
11062
|
-
}
|
|
11063
|
-
}
|
|
11064
|
-
return {
|
|
11065
|
-
enabled: false
|
|
11066
|
-
};
|
|
11067
|
-
}
|
|
11068
|
-
async function setGitRemoteGithubRepoUrl(owner, repo, token, cwd = process.cwd()) {
|
|
11069
|
-
const {
|
|
11070
|
-
GITHUB_SERVER_URL
|
|
11071
|
-
} = constants.default.ENV;
|
|
11072
|
-
const urlObj = parseUrl(GITHUB_SERVER_URL);
|
|
11073
|
-
const host = urlObj?.host;
|
|
11074
|
-
if (!host) {
|
|
11075
|
-
debugFn('error', 'invalid: GITHUB_SERVER_URL env var');
|
|
11076
|
-
debugDir('inspect', {
|
|
11077
|
-
GITHUB_SERVER_URL
|
|
11078
|
-
});
|
|
11079
|
-
return false;
|
|
11080
|
-
}
|
|
11081
|
-
const url = `https://x-access-token:${token}@${host}/${owner}/${repo}`;
|
|
11082
|
-
const stdioIgnoreOptions = {
|
|
11083
|
-
cwd,
|
|
11084
|
-
stdio: isDebug('stdio') ? 'inherit' : 'ignore'
|
|
11085
|
-
};
|
|
11086
|
-
const quotedCmd = `\`git remote set-url origin ${url}\``;
|
|
11087
|
-
debugFn('stdio', `spawn: ${quotedCmd}`);
|
|
11088
|
-
try {
|
|
11089
|
-
await spawn('git', ['remote', 'set-url', 'origin', url], stdioIgnoreOptions);
|
|
11090
|
-
return true;
|
|
11091
|
-
} catch (e) {
|
|
11092
|
-
debugFn('error', `Git command failed: ${quotedCmd}`);
|
|
11093
|
-
debugDir('inspect', {
|
|
11094
|
-
cmd: quotedCmd
|
|
11095
|
-
});
|
|
11096
|
-
debugDir('error', e);
|
|
11097
|
-
}
|
|
11098
|
-
return false;
|
|
11099
|
-
}
|
|
11100
|
-
|
|
11101
11175
|
const CVE_FORMAT_REGEXP = /^CVE-\d{4}-\d{4,}$/;
|
|
11102
11176
|
const GHSA_FORMAT_REGEXP = /^GHSA-[a-z0-9]{4}-[a-z0-9]{4}-[a-z0-9]{4}$/;
|
|
11103
11177
|
|
|
@@ -13956,6 +14030,7 @@ exports.BUILD_FILES = BUILD_FILES;
|
|
|
13956
14030
|
exports.BUILD_TOOLS = BUILD_TOOLS;
|
|
13957
14031
|
exports.COMPLETION_CMD_PREFIX = COMPLETION_CMD_PREFIX;
|
|
13958
14032
|
exports.CVE_FORMAT_REGEXP = CVE_FORMAT_REGEXP;
|
|
14033
|
+
exports.DISABLE_DEPENDENCY_DOWNLOADS_FLAG = DISABLE_DEPENDENCY_DOWNLOADS_FLAG;
|
|
13959
14034
|
exports.ECOSYSTEM_LABELS = ECOSYSTEM_LABELS;
|
|
13960
14035
|
exports.FACTS_PURL_TYPES = FACTS_PURL_TYPES;
|
|
13961
14036
|
exports.GHSA_FORMAT_REGEXP = GHSA_FORMAT_REGEXP;
|
|
@@ -14062,6 +14137,7 @@ exports.githubApiRequest = githubApiRequest;
|
|
|
14062
14137
|
exports.globWithGitIgnore = globWithGitIgnore;
|
|
14063
14138
|
exports.globWorkspace = globWorkspace;
|
|
14064
14139
|
exports.handleApiCall = handleApiCall;
|
|
14140
|
+
exports.hasCiExitCodePolicy = hasCiExitCodePolicy;
|
|
14065
14141
|
exports.hasDefaultApiToken = hasDefaultApiToken;
|
|
14066
14142
|
exports.hasEnterpriseOrgPlan = hasEnterpriseOrgPlan;
|
|
14067
14143
|
exports.hasKeys = hasKeys;
|
|
@@ -14153,6 +14229,8 @@ exports.saveOAuthCredentials = saveOAuthCredentials;
|
|
|
14153
14229
|
exports.select = select;
|
|
14154
14230
|
exports.sendApiRequest = sendApiRequest;
|
|
14155
14231
|
exports.serializeResultJson = serializeResultJson;
|
|
14232
|
+
exports.setCiExitCode = setCiExitCode;
|
|
14233
|
+
exports.setCiExitCodePolicy = setCiExitCodePolicy;
|
|
14156
14234
|
exports.setGitRemoteGithubRepoUrl = setGitRemoteGithubRepoUrl;
|
|
14157
14235
|
exports.setupSdk = setupSdk;
|
|
14158
14236
|
exports.setupTelemetryExitHandlers = setupTelemetryExitHandlers;
|
|
@@ -14176,10 +14254,11 @@ exports.trackCliStart = trackCliStart;
|
|
|
14176
14254
|
exports.trackSubprocessExit = trackSubprocessExit;
|
|
14177
14255
|
exports.trackSubprocessStart = trackSubprocessStart;
|
|
14178
14256
|
exports.updateConfigValue = updateConfigValue;
|
|
14257
|
+
exports.upsertPullRequestComment = upsertPullRequestComment;
|
|
14179
14258
|
exports.useOnlySocketFactsArtifactsFlags = useOnlySocketFactsArtifactsFlags;
|
|
14180
14259
|
exports.walkNestedMap = walkNestedMap;
|
|
14181
14260
|
exports.webLink = webLink;
|
|
14182
14261
|
exports.withTmpDir = withTmpDir;
|
|
14183
14262
|
exports.writeSocketJson = writeSocketJson;
|
|
14184
|
-
//# debugId=
|
|
14263
|
+
//# debugId=8242101c-bdc7-464f-b3b2-fd30dd0e4cef
|
|
14185
14264
|
//# sourceMappingURL=utils.js.map
|