@@ -2,7 +2,6 @@ import * as fs from "fs";
22import * as os from "os" ;
33import * as path from "path" ;
44
5- import * as core from "@actions/core" ;
65import * as exec from "@actions/exec" ;
76
87import { Logger } from "./logging" ;
@@ -64,31 +63,6 @@ function scanFileForTokens(
6463) : TokenFinding [ ] {
6564 const findings : TokenFinding [ ] = [ ] ;
6665 try {
67- // Skip binary files that are unlikely to contain tokens
68- const ext = path . extname ( filePath ) . toLowerCase ( ) ;
69- const binaryExtensions = [
70- ".zip" ,
71- ".tar" ,
72- ".gz" ,
73- ".bz2" ,
74- ".xz" ,
75- ".db" ,
76- ".sqlite" ,
77- ".bin" ,
78- ".exe" ,
79- ".dll" ,
80- ".so" ,
81- ".dylib" ,
82- ".jpg" ,
83- ".jpeg" ,
84- ".png" ,
85- ".gif" ,
86- ".pdf" ,
87- ] ;
88- if ( binaryExtensions . includes ( ext ) ) {
89- return [ ] ;
90- }
91-
9266 const content = fs . readFileSync ( filePath , "utf8" ) ;
9367
9468 for ( const { name, pattern } of GITHUB_TOKEN_PATTERNS ) {
@@ -130,13 +104,9 @@ async function scanZipFile(
130104) : Promise < ScanResult > {
131105 const MAX_DEPTH = 10 ; // Prevent infinite recursion
132106 if ( depth > MAX_DEPTH ) {
133- logger . warning (
107+ throw new Error (
134108 `Maximum zip extraction depth (${ MAX_DEPTH } ) reached for ${ zipPath } ` ,
135109 ) ;
136- return {
137- scannedFiles : 0 ,
138- findings : [ ] ,
139- } ;
140110 }
141111
142112 const result : ScanResult = {
@@ -237,38 +207,32 @@ async function scanDirectory(
237207 findings : [ ] ,
238208 } ;
239209
240- try {
241- const entries = fs . readdirSync ( dirPath , { withFileTypes : true } ) ;
210+ const entries = fs . readdirSync ( dirPath , { withFileTypes : true } ) ;
242211
243- for ( const entry of entries ) {
244- const fullPath = path . join ( dirPath , entry . name ) ;
245- const relativePath = path . join ( baseRelativePath , entry . name ) ;
212+ for ( const entry of entries ) {
213+ const fullPath = path . join ( dirPath , entry . name ) ;
214+ const relativePath = path . join ( baseRelativePath , entry . name ) ;
246215
247- if ( entry . isDirectory ( ) ) {
248- const subResult = await scanDirectory (
249- fullPath ,
250- relativePath ,
251- logger ,
252- depth ,
253- ) ;
254- result . scannedFiles += subResult . scannedFiles ;
255- result . findings . push ( ...subResult . findings ) ;
256- } else if ( entry . isFile ( ) ) {
257- const fileResult = await scanFile (
258- fullPath ,
259- relativePath ,
260- path . dirname ( fullPath ) ,
261- logger ,
262- depth ,
263- ) ;
264- result . scannedFiles += fileResult . scannedFiles ;
265- result . findings . push ( ...fileResult . findings ) ;
266- }
216+ if ( entry . isDirectory ( ) ) {
217+ const subResult = await scanDirectory (
218+ fullPath ,
219+ relativePath ,
220+ logger ,
221+ depth ,
222+ ) ;
223+ result . scannedFiles += subResult . scannedFiles ;
224+ result . findings . push ( ...subResult . findings ) ;
225+ } else if ( entry . isFile ( ) ) {
226+ const fileResult = await scanFile (
227+ fullPath ,
228+ relativePath ,
229+ path . dirname ( fullPath ) ,
230+ logger ,
231+ depth ,
232+ ) ;
233+ result . scannedFiles += fileResult . scannedFiles ;
234+ result . findings . push ( ...fileResult . findings ) ;
267235 }
268- } catch ( e ) {
269- logger . warning (
270- `Error scanning directory ${ dirPath } : ${ getErrorMessage ( e ) } ` ,
271- ) ;
272236 }
273237
274238 return result ;
@@ -285,8 +249,10 @@ async function scanDirectory(
285249export async function scanArtifactsForTokens (
286250 filesToScan : string [ ] ,
287251 logger : Logger ,
288- ) : Promise < ScanResult > {
289- logger . info ( "Starting security scan for GitHub tokens in debug artifacts..." ) ;
252+ ) : Promise < void > {
253+ logger . info (
254+ "Starting best-effort check for potential GitHub tokens in debug artifacts (for testing purposes only)..." ,
255+ ) ;
290256
291257 const result : ScanResult = {
292258 scannedFiles : 0 ,
@@ -298,26 +264,22 @@ export async function scanArtifactsForTokens(
298264
299265 try {
300266 for ( const filePath of filesToScan ) {
301- try {
302- const stats = fs . statSync ( filePath ) ;
303- const fileName = path . basename ( filePath ) ;
304-
305- if ( stats . isDirectory ( ) ) {
306- const dirResult = await scanDirectory ( filePath , fileName , logger ) ;
307- result . scannedFiles += dirResult . scannedFiles ;
308- result . findings . push ( ...dirResult . findings ) ;
309- } else if ( stats . isFile ( ) ) {
310- const fileResult = await scanFile (
311- filePath ,
312- fileName ,
313- tempScanDir ,
314- logger ,
315- ) ;
316- result . scannedFiles += fileResult . scannedFiles ;
317- result . findings . push ( ...fileResult . findings ) ;
318- }
319- } catch ( e ) {
320- logger . warning ( `Error scanning ${ filePath } : ${ getErrorMessage ( e ) } ` ) ;
267+ const stats = fs . statSync ( filePath ) ;
268+ const fileName = path . basename ( filePath ) ;
269+
270+ if ( stats . isDirectory ( ) ) {
271+ const dirResult = await scanDirectory ( filePath , fileName , logger ) ;
272+ result . scannedFiles += dirResult . scannedFiles ;
273+ result . findings . push ( ...dirResult . findings ) ;
274+ } else if ( stats . isFile ( ) ) {
275+ const fileResult = await scanFile (
276+ filePath ,
277+ fileName ,
278+ tempScanDir ,
279+ logger ,
280+ ) ;
281+ result . scannedFiles += fileResult . scannedFiles ;
282+ result . findings . push ( ...fileResult . findings ) ;
321283 }
322284 }
323285
@@ -341,12 +303,12 @@ export async function scanArtifactsForTokens(
341303 ? `${ baseSummary } (${ tokenTypesSummary } )`
342304 : baseSummary ;
343305
344- logger . info ( `Security scan complete: ${ summaryWithTypes } ` ) ;
306+ logger . info ( `Artifact check complete: ${ summaryWithTypes } ` ) ;
345307
346308 if ( result . findings . length > 0 ) {
347309 const fileList = Array . from ( filesWithTokens ) . join ( ", " ) ;
348- core . warning (
349- `Found ${ result . findings . length } potential GitHub token(s) (${ tokenTypesSummary } ) in debug artifacts at: ${ fileList } . This may indicate a security issue. Please review the artifacts before sharing .` ,
310+ throw new Error (
311+ `Found ${ result . findings . length } potential GitHub token(s) (${ tokenTypesSummary } ) in debug artifacts at: ${ fileList } . This is a best-effort check for testing purposes only .` ,
350312 ) ;
351313 }
352314 } finally {
@@ -359,6 +321,4 @@ export async function scanArtifactsForTokens(
359321 ) ;
360322 }
361323 }
362-
363- return result ;
364324}
0 commit comments