2020-04-28 16:46:47 +02:00
"use strict" ;
2021-07-27 17:59:59 +01:00
var _ _createBinding = ( this && this . _ _createBinding ) || ( Object . create ? ( function ( o , m , k , k2 ) {
if ( k2 === undefined ) k2 = k ;
Object . defineProperty ( o , k2 , { enumerable : true , get : function ( ) { return m [ k ] ; } } ) ;
} ) : ( function ( o , m , k , k2 ) {
if ( k2 === undefined ) k2 = k ;
o [ k2 ] = m [ k ] ;
} ) ) ;
var _ _setModuleDefault = ( this && this . _ _setModuleDefault ) || ( Object . create ? ( function ( o , v ) {
Object . defineProperty ( o , "default" , { enumerable : true , value : v } ) ;
} ) : function ( o , v ) {
o [ "default" ] = v ;
} ) ;
2020-04-28 16:46:47 +02:00
var _ _importStar = ( this && this . _ _importStar ) || function ( mod ) {
if ( mod && mod . _ _esModule ) return mod ;
var result = { } ;
2021-07-27 17:59:59 +01:00
if ( mod != null ) for ( var k in mod ) if ( k !== "default" && Object . prototype . hasOwnProperty . call ( mod , k ) ) _ _createBinding ( result , mod , k ) ;
_ _setModuleDefault ( result , mod ) ;
2020-04-28 16:46:47 +02:00
return result ;
} ;
2020-08-12 17:42:47 +01:00
var _ _importDefault = ( this && this . _ _importDefault ) || function ( mod ) {
return ( mod && mod . _ _esModule ) ? mod : { "default" : mod } ;
} ;
2020-04-28 16:46:47 +02:00
Object . defineProperty ( exports , "__esModule" , { value : true } ) ;
2022-11-14 18:55:31 +00:00
exports . pruneInvalidResults = exports . validateUniqueCategory = exports . waitForProcessing = exports . buildPayload = exports . validateSarifFileSchema = exports . countResultsInSarif = exports . uploadFromActions = exports . findSarifFilesInDir = exports . populateRunAutomationDetails = exports . combineSarifFiles = void 0 ;
2020-04-28 16:46:47 +02:00
const fs = _ _importStar ( require ( "fs" ) ) ;
const path = _ _importStar ( require ( "path" ) ) ;
2022-11-04 13:58:27 +00:00
const process _1 = require ( "process" ) ;
2020-10-01 11:03:30 +01:00
const zlib _1 = _ _importDefault ( require ( "zlib" ) ) ;
const core = _ _importStar ( require ( "@actions/core" ) ) ;
const file _url _1 = _ _importDefault ( require ( "file-url" ) ) ;
const jsonschema = _ _importStar ( require ( "jsonschema" ) ) ;
2021-01-28 15:37:09 +00:00
const actionsUtil = _ _importStar ( require ( "./actions-util" ) ) ;
2020-10-01 11:03:30 +01:00
const api = _ _importStar ( require ( "./api-client" ) ) ;
const fingerprints = _ _importStar ( require ( "./fingerprints" ) ) ;
2021-01-28 15:37:09 +00:00
const repository _1 = require ( "./repository" ) ;
2020-08-12 17:42:47 +01:00
const sharedEnv = _ _importStar ( require ( "./shared-environment" ) ) ;
2020-04-28 16:46:47 +02:00
const util = _ _importStar ( require ( "./util" ) ) ;
// Takes a list of paths to sarif files and combines them together,
// returning the contents of the combined sarif file.
function combineSarifFiles ( sarifFiles ) {
2020-09-14 10:44:43 +01:00
const combinedSarif = {
2020-04-28 16:46:47 +02:00
version : null ,
2020-09-14 10:44:43 +01:00
runs : [ ] ,
2020-04-28 16:46:47 +02:00
} ;
2020-09-14 10:44:43 +01:00
for ( const sarifFile of sarifFiles ) {
const sarifObject = JSON . parse ( fs . readFileSync ( sarifFile , "utf8" ) ) ;
2020-04-28 16:46:47 +02:00
// Check SARIF version
if ( combinedSarif . version === null ) {
combinedSarif . version = sarifObject . version ;
}
else if ( combinedSarif . version !== sarifObject . version ) {
2020-09-25 17:39:25 +08:00
throw new Error ( ` Different SARIF versions encountered: ${ combinedSarif . version } and ${ sarifObject . version } ` ) ;
2020-04-28 16:46:47 +02:00
}
combinedSarif . runs . push ( ... sarifObject . runs ) ;
}
2022-01-12 15:26:34 -08:00
return combinedSarif ;
2020-04-28 16:46:47 +02:00
}
exports . combineSarifFiles = combineSarifFiles ;
2021-04-15 16:20:49 +02:00
// Populates the run.automationDetails.id field using the analysis_key and environment
// and return an updated sarif file contents.
2022-01-12 15:26:34 -08:00
function populateRunAutomationDetails ( sarif , category , analysis _key , environment ) {
2021-04-28 14:32:16 +02:00
const automationID = getAutomationID ( category , analysis _key , environment ) ;
2022-01-12 15:26:34 -08:00
if ( automationID !== undefined ) {
for ( const run of sarif . runs || [ ] ) {
if ( run . automationDetails === undefined ) {
run . automationDetails = {
id : automationID ,
} ;
}
2021-04-28 14:32:16 +02:00
}
2022-01-12 15:26:34 -08:00
return sarif ;
2021-04-28 14:32:16 +02:00
}
2022-01-12 15:26:34 -08:00
return sarif ;
2021-04-28 14:32:16 +02:00
}
exports . populateRunAutomationDetails = populateRunAutomationDetails ;
function getAutomationID ( category , analysis _key , environment ) {
if ( category !== undefined ) {
let automationID = category ;
if ( ! automationID . endsWith ( "/" ) ) {
automationID += "/" ;
}
return automationID ;
}
2022-11-14 18:55:31 +00:00
return actionsUtil . computeAutomationID ( analysis _key , environment ) ;
2021-04-15 16:20:49 +02:00
}
2020-05-01 10:39:23 +01:00
// Upload the given payload.
2020-05-01 11:19:39 +01:00
// If the request fails then this will retry a small number of times.
2022-11-14 19:48:27 +00:00
async function uploadPayload ( payload , repositoryNwo , logger ) {
2020-09-14 10:44:43 +01:00
logger . info ( "Uploading results" ) ;
2020-05-08 16:06:35 +02:00
// If in test mode we don't want to upload the results
2022-04-28 19:07:04 +01:00
if ( util . isInTestMode ( ) ) {
2022-02-28 11:56:11 -08:00
const payloadSaveFile = path . join ( actionsUtil . getTemporaryDirectory ( ) , "payload.json" ) ;
logger . info ( ` In test mode. Results are not uploaded. Saving to ${ payloadSaveFile } ` ) ;
logger . info ( ` Payload: ${ JSON . stringify ( payload , null , 2 ) } ` ) ;
fs . writeFileSync ( payloadSaveFile , JSON . stringify ( payload , null , 2 ) ) ;
2020-07-20 16:33:37 +01:00
return ;
2020-05-08 16:06:35 +02:00
}
2022-11-14 19:48:27 +00:00
const client = api . getApiClient ( ) ;
2022-11-14 16:37:48 +00:00
const response = await client . request ( "PUT /repos/:owner/:repo/code-scanning/analysis" , {
2020-09-21 11:06:21 +01:00
owner : repositoryNwo . owner ,
repo : repositoryNwo . repo ,
data : payload ,
} ) ;
logger . debug ( ` response status: ${ response . status } ` ) ;
logger . info ( "Successfully uploaded results" ) ;
2021-10-18 11:43:30 +01:00
return response . data . id ;
2020-05-01 10:39:23 +01:00
}
2021-01-04 13:12:30 +00:00
// Recursively walks a directory and returns all SARIF files it finds.
// Does not follow symlinks.
function findSarifFilesInDir ( sarifPath ) {
const sarifFiles = [ ] ;
const walkSarifFiles = ( dir ) => {
const entries = fs . readdirSync ( dir , { withFileTypes : true } ) ;
for ( const entry of entries ) {
if ( entry . isFile ( ) && entry . name . endsWith ( ".sarif" ) ) {
sarifFiles . push ( path . resolve ( dir , entry . name ) ) ;
}
else if ( entry . isDirectory ( ) ) {
walkSarifFiles ( path . resolve ( dir , entry . name ) ) ;
}
}
} ;
walkSarifFiles ( sarifPath ) ;
return sarifFiles ;
}
exports . findSarifFilesInDir = findSarifFilesInDir ;
2020-04-28 16:46:47 +02:00
// Uploads a single sarif file or a directory of sarif files
// depending on what the path happens to refer to.
2020-04-30 16:28:53 +01:00
// Returns true iff the upload occurred and succeeded
2022-11-23 13:57:07 +00:00
async function uploadFromActions ( sarifPath , logger ) {
return await uploadFiles ( getSarifFilePaths ( sarifPath ) , ( 0 , repository _1 . parseRepositoryNwo ) ( util . getRequiredEnvParam ( "GITHUB_REPOSITORY" ) ) , await actionsUtil . getCommitOid ( actionsUtil . getRequiredInput ( "checkout_path" ) ) , await actionsUtil . getRef ( ) , await actionsUtil . getAnalysisKey ( ) , actionsUtil . getOptionalInput ( "category" ) , util . getRequiredEnvParam ( "GITHUB_WORKFLOW" ) , actionsUtil . getWorkflowRunID ( ) , actionsUtil . getRequiredInput ( "checkout_path" ) , actionsUtil . getRequiredInput ( "matrix" ) , logger ) ;
2020-11-26 11:37:50 +00:00
}
exports . uploadFromActions = uploadFromActions ;
function getSarifFilePaths ( sarifPath ) {
2020-08-12 18:00:01 +01:00
if ( ! fs . existsSync ( sarifPath ) ) {
throw new Error ( ` Path does not exist: ${ sarifPath } ` ) ;
}
2021-01-04 13:12:30 +00:00
let sarifFiles ;
2020-08-12 17:42:47 +01:00
if ( fs . lstatSync ( sarifPath ) . isDirectory ( ) ) {
2021-01-04 13:12:30 +00:00
sarifFiles = findSarifFilesInDir ( sarifPath ) ;
2020-05-01 11:12:15 +01:00
if ( sarifFiles . length === 0 ) {
2020-09-14 10:44:43 +01:00
throw new Error ( ` No SARIF files found to upload in " ${ sarifPath } ". ` ) ;
2020-05-01 11:12:15 +01:00
}
2020-04-28 16:46:47 +02:00
}
else {
2021-01-04 13:12:30 +00:00
sarifFiles = [ sarifPath ] ;
2020-04-28 16:46:47 +02:00
}
2020-11-26 11:37:50 +00:00
return sarifFiles ;
2020-04-28 16:46:47 +02:00
}
2020-05-15 17:25:34 +01:00
// Counts the number of results in the given SARIF file
function countResultsInSarif ( sarif ) {
let numResults = 0 ;
2021-03-17 09:36:00 -07:00
let parsedSarif ;
try {
parsedSarif = JSON . parse ( sarif ) ;
}
catch ( e ) {
2021-09-10 13:53:13 -07:00
throw new Error ( ` Invalid SARIF. JSON syntax error: ${ e instanceof Error ? e . message : String ( e ) } ` ) ;
2021-03-17 09:36:00 -07:00
}
if ( ! Array . isArray ( parsedSarif . runs ) ) {
throw new Error ( "Invalid SARIF. Missing 'runs' array." ) ;
}
for ( const run of parsedSarif . runs ) {
if ( ! Array . isArray ( run . results ) ) {
throw new Error ( "Invalid SARIF. Missing 'results' array in run." ) ;
}
2020-05-15 17:25:34 +01:00
numResults += run . results . length ;
}
return numResults ;
}
exports . countResultsInSarif = countResultsInSarif ;
2020-05-15 17:22:59 +01:00
// Validates that the given file path refers to a valid SARIF file.
2020-07-20 16:33:37 +01:00
// Throws an error if the file is invalid.
2020-08-11 12:43:27 +01:00
function validateSarifFileSchema ( sarifFilePath , logger ) {
2020-09-14 10:44:43 +01:00
const sarif = JSON . parse ( fs . readFileSync ( sarifFilePath , "utf8" ) ) ;
const schema = require ( "../src/sarif_v2.1.0_schema.json" ) ;
2020-05-15 17:22:59 +01:00
const result = new jsonschema . Validator ( ) . validate ( sarif , schema ) ;
2020-07-20 16:33:37 +01:00
if ( ! result . valid ) {
// Output the more verbose error messages in groups as these may be very large.
2020-05-22 14:56:20 +01:00
for ( const error of result . errors ) {
2020-09-14 10:44:43 +01:00
logger . startGroup ( ` Error details: ${ error . stack } ` ) ;
2020-08-11 12:43:27 +01:00
logger . info ( JSON . stringify ( error , null , 2 ) ) ;
logger . endGroup ( ) ;
2020-05-22 14:56:20 +01:00
}
2020-07-20 16:33:37 +01:00
// Set the main error message to the stacks of all the errors.
// This should be of a manageable size and may even give enough to fix the error.
2020-09-14 10:44:43 +01:00
const sarifErrors = result . errors . map ( ( e ) => ` - ${ e . stack } ` ) ;
throw new Error ( ` Unable to upload " ${ sarifFilePath } " as it is not valid SARIF: \n ${ sarifErrors . join ( "\n" ) } ` ) ;
2020-05-15 17:22:59 +01:00
}
}
exports . validateSarifFileSchema = validateSarifFileSchema ;
2020-11-30 16:33:38 +00:00
// buildPayload constructs a map ready to be uploaded to the API from the given
// parameters, respecting the current mode and target GitHub instance version.
2022-11-23 13:57:07 +00:00
function buildPayload ( commitOid , ref , analysisKey , analysisName , zippedSarif , workflowRunID , checkoutURI , environment , toolNames , mergeBaseCommitOid ) {
2022-11-14 16:37:48 +00:00
const payloadObj = {
commit _oid : commitOid ,
ref ,
analysis _key : analysisKey ,
analysis _name : analysisName ,
sarif : zippedSarif ,
workflow _run _id : workflowRunID ,
checkout _uri : checkoutURI ,
environment ,
started _at : process . env [ sharedEnv . CODEQL _WORKFLOW _STARTED _AT ] ,
tool _names : toolNames ,
base _ref : undefined ,
base _sha : undefined ,
} ;
2022-11-23 13:57:07 +00:00
if ( actionsUtil . workflowEventName ( ) === "pull_request" ) {
if ( commitOid === util . getRequiredEnvParam ( "GITHUB_SHA" ) &&
mergeBaseCommitOid ) {
// We're uploading results for the merge commit
// and were able to determine the merge base.
// So we use that as the most accurate base.
payloadObj . base _ref = ` refs/heads/ ${ util . getRequiredEnvParam ( "GITHUB_BASE_REF" ) } ` ;
payloadObj . base _sha = mergeBaseCommitOid ;
}
else if ( process . env . GITHUB _EVENT _PATH ) {
// Either we're not uploading results for the merge commit
// or we could not determine the merge base.
// Using the PR base is the only option here
const githubEvent = JSON . parse ( fs . readFileSync ( process . env . GITHUB _EVENT _PATH , "utf8" ) ) ;
payloadObj . base _ref = ` refs/heads/ ${ githubEvent . pull _request . base . ref } ` ;
payloadObj . base _sha = githubEvent . pull _request . base . sha ;
2020-11-26 17:54:34 +00:00
}
2020-04-28 16:46:47 +02:00
}
2022-11-14 16:37:48 +00:00
return payloadObj ;
2020-11-30 16:33:38 +00:00
}
exports . buildPayload = buildPayload ;
2020-04-28 16:46:47 +02:00
// Uploads the given set of sarif files.
2020-04-30 16:28:53 +01:00
// Returns true iff the upload occurred and succeeded
2022-11-23 13:57:07 +00:00
async function uploadFiles ( sarifFiles , repositoryNwo , commitOid , ref , analysisKey , category , analysisName , workflowRunID , sourceRoot , environment , logger ) {
2021-05-19 17:04:58 -07:00
logger . startGroup ( "Uploading results" ) ;
logger . info ( ` Processing sarif files: ${ JSON . stringify ( sarifFiles ) } ` ) ;
2020-06-15 14:40:01 +01:00
// Validate that the files we were asked to upload are all valid SARIF files
for ( const file of sarifFiles ) {
2020-08-11 12:43:27 +01:00
validateSarifFileSchema ( file , logger ) ;
2020-04-28 16:46:47 +02:00
}
2022-01-12 15:26:34 -08:00
let sarif = combineSarifFiles ( sarifFiles ) ;
sarif = await fingerprints . addFingerprints ( sarif , sourceRoot , logger ) ;
sarif = populateRunAutomationDetails ( sarif , category , analysisKey , environment ) ;
2022-11-04 13:58:27 +00:00
if ( process _1 . env [ "CODEQL_DISABLE_SARIF_PRUNING" ] !== "true" )
sarif = pruneInvalidResults ( sarif , logger ) ;
2022-01-12 15:26:34 -08:00
const toolNames = util . getToolNames ( sarif ) ;
validateUniqueCategory ( sarif ) ;
const sarifPayload = JSON . stringify ( sarif ) ;
2020-11-30 16:33:38 +00:00
const zippedSarif = zlib _1 . default . gzipSync ( sarifPayload ) . toString ( "base64" ) ;
2021-09-10 13:53:13 -07:00
const checkoutURI = ( 0 , file _url _1 . default ) ( sourceRoot ) ;
2022-11-23 13:57:07 +00:00
const payload = buildPayload ( commitOid , ref , analysisKey , analysisName , zippedSarif , workflowRunID , checkoutURI , environment , toolNames , await actionsUtil . determineMergeBaseCommitOid ( ) ) ;
2020-05-28 10:40:26 +01:00
// Log some useful debug info about the info
2020-07-20 16:33:37 +01:00
const rawUploadSizeBytes = sarifPayload . length ;
2020-09-14 10:44:43 +01:00
logger . debug ( ` Raw upload size: ${ rawUploadSizeBytes } bytes ` ) ;
2020-11-30 16:33:38 +00:00
const zippedUploadSizeBytes = zippedSarif . length ;
2020-09-14 10:44:43 +01:00
logger . debug ( ` Base64 zipped upload size: ${ zippedUploadSizeBytes } bytes ` ) ;
2020-07-20 16:33:37 +01:00
const numResultInSarif = countResultsInSarif ( sarifPayload ) ;
2020-09-14 10:44:43 +01:00
logger . debug ( ` Number of results in upload: ${ numResultInSarif } ` ) ;
2020-08-11 12:43:27 +01:00
// Make the upload
2022-11-14 19:48:27 +00:00
const sarifID = await uploadPayload ( payload , repositoryNwo , logger ) ;
2021-05-19 17:04:58 -07:00
logger . endGroup ( ) ;
2021-11-17 13:20:36 +00:00
return {
statusReport : {
raw _upload _size _bytes : rawUploadSizeBytes ,
zipped _upload _size _bytes : zippedUploadSizeBytes ,
num _results _in _sarif : numResultInSarif ,
} ,
sarifID ,
} ;
}
const STATUS _CHECK _FREQUENCY _MILLISECONDS = 5 * 1000 ;
const STATUS _CHECK _TIMEOUT _MILLISECONDS = 2 * 60 * 1000 ;
// Waits until either the analysis is successfully processed, a processing error is reported, or STATUS_CHECK_TIMEOUT_MILLISECONDS elapses.
2022-11-14 19:48:27 +00:00
async function waitForProcessing ( repositoryNwo , sarifID , logger ) {
2021-11-17 13:20:36 +00:00
logger . startGroup ( "Waiting for processing to finish" ) ;
2022-11-14 19:48:27 +00:00
const client = api . getApiClient ( ) ;
2021-11-17 13:20:36 +00:00
const statusCheckingStarted = Date . now ( ) ;
// eslint-disable-next-line no-constant-condition
while ( true ) {
if ( Date . now ( ) >
statusCheckingStarted + STATUS _CHECK _TIMEOUT _MILLISECONDS ) {
// If the analysis hasn't finished processing in the allotted time, we continue anyway rather than failing.
// It's possible the analysis will eventually finish processing, but it's not worth spending more Actions time waiting.
logger . warning ( "Timed out waiting for analysis to finish processing. Continuing." ) ;
break ;
}
2022-05-03 09:42:15 +01:00
let response = undefined ;
2021-11-17 13:20:36 +00:00
try {
2022-05-03 09:42:15 +01:00
response = await client . request ( "GET /repos/:owner/:repo/code-scanning/sarifs/:sarif_id" , {
2021-11-17 13:20:36 +00:00
owner : repositoryNwo . owner ,
repo : repositoryNwo . repo ,
sarif _id : sarifID ,
} ) ;
}
catch ( e ) {
2022-03-30 10:55:22 +01:00
logger . warning ( ` An error occurred checking the status of the delivery. ${ e } It should still be processed in the background, but errors that occur during processing may not be reported. ` ) ;
2022-05-03 09:42:15 +01:00
break ;
}
const status = response . data . processing _status ;
logger . info ( ` Analysis upload status is ${ status } . ` ) ;
if ( status === "complete" ) {
break ;
}
else if ( status === "pending" ) {
logger . debug ( "Analysis processing is still pending..." ) ;
}
else if ( status === "failed" ) {
throw new Error ( ` Code Scanning could not process the submitted SARIF file: \n ${ response . data . errors } ` ) ;
2021-10-18 11:43:30 +01:00
}
2021-11-17 15:51:50 +00:00
await util . delay ( STATUS _CHECK _FREQUENCY _MILLISECONDS ) ;
2021-10-18 11:43:30 +01:00
}
2021-11-17 13:20:36 +00:00
logger . endGroup ( ) ;
2020-04-28 16:46:47 +02:00
}
2021-11-17 13:20:36 +00:00
exports . waitForProcessing = waitForProcessing ;
2022-01-12 15:26:34 -08:00
function validateUniqueCategory ( sarif ) {
var _a , _b , _c ;
2022-11-14 16:37:48 +00:00
// duplicate categories are allowed in the same sarif file
// but not across multiple sarif files
const categories = { } ;
for ( const run of sarif . runs ) {
const id = ( _a = run === null || run === void 0 ? void 0 : run . automationDetails ) === null || _a === void 0 ? void 0 : _a . id ;
const tool = ( _c = ( _b = run . tool ) === null || _b === void 0 ? void 0 : _b . driver ) === null || _c === void 0 ? void 0 : _c . name ;
const category = ` ${ sanitize ( id ) } _ ${ sanitize ( tool ) } ` ;
categories [ category ] = { id , tool } ;
}
for ( const [ category , { id , tool } ] of Object . entries ( categories ) ) {
const sentinelEnvVar = ` CODEQL_UPLOAD_SARIF_ ${ category } ` ;
if ( process . env [ sentinelEnvVar ] ) {
throw new Error ( "Aborting upload: only one run of the codeql/analyze or codeql/upload-sarif actions is allowed per job per tool/category. " +
"The easiest fix is to specify a unique value for the `category` input. If .runs[].automationDetails.id is specified " +
"in the sarif file, that will take precedence over your configured `category`. " +
` Category: ( ${ id ? id : "none" } ) Tool: ( ${ tool ? tool : "none" } ) ` ) ;
2021-10-29 11:31:30 -07:00
}
2022-11-14 16:37:48 +00:00
core . exportVariable ( sentinelEnvVar , sentinelEnvVar ) ;
2021-10-29 11:31:30 -07:00
}
}
exports . validateUniqueCategory = validateUniqueCategory ;
/**
* Santizes a string to be used as an environment variable name.
* This will replace all non-alphanumeric characters with underscores.
* There could still be some false category clashes if two uploads
* occur that differ only in their non-alphanumeric characters. This is
* unlikely.
*
* @param str the initial value to sanitize
*/
function sanitize ( str ) {
2022-01-12 15:26:34 -08:00
return ( str !== null && str !== void 0 ? str : "_" ) . replace ( /[^a-zA-Z0-9_]/g , "_" ) . toLocaleUpperCase ( ) ;
2021-10-29 11:31:30 -07:00
}
2022-11-04 13:58:27 +00:00
function pruneInvalidResults ( sarif , logger ) {
var _a , _b , _c , _d , _e , _f , _g , _h ;
let pruned = 0 ;
const newRuns = [ ] ;
for ( const run of sarif . runs || [ ] ) {
if ( ( ( _b = ( _a = run . tool ) === null || _a === void 0 ? void 0 : _a . driver ) === null || _b === void 0 ? void 0 : _b . name ) === "CodeQL" &&
( ( _d = ( _c = run . tool ) === null || _c === void 0 ? void 0 : _c . driver ) === null || _d === void 0 ? void 0 : _d . semanticVersion ) === "2.11.2" ) {
// Version 2.11.2 of the CodeQL CLI had many false positives in the
// rb/weak-cryptographic-algorithm query which we prune here. The
// issue is tracked in https://github.com/github/codeql/issues/11107.
const newResults = [ ] ;
for ( const result of run . results || [ ] ) {
if ( result . ruleId === "rb/weak-cryptographic-algorithm" &&
( ( ( _f = ( _e = result . message ) === null || _e === void 0 ? void 0 : _e . text ) === null || _f === void 0 ? void 0 : _f . includes ( " MD5 " ) ) ||
( ( _h = ( _g = result . message ) === null || _g === void 0 ? void 0 : _g . text ) === null || _h === void 0 ? void 0 : _h . includes ( " SHA1 " ) ) ) ) {
pruned += 1 ;
continue ;
}
newResults . push ( result ) ;
}
newRuns . push ( { ... run , results : newResults } ) ;
}
else {
newRuns . push ( run ) ;
}
}
if ( pruned > 0 ) {
logger . info ( ` Pruned ${ pruned } results believed to be invalid from SARIF file. ` ) ;
}
return { ... sarif , runs : newRuns } ;
}
exports . pruneInvalidResults = pruneInvalidResults ;
2020-05-13 16:31:24 +01:00
//# sourceMappingURL=upload-lib.js.map