@@ -13,22 +13,100 @@ GOSEC_RULES=${INPUT_GOSEC_RULES:-}
1313TRIVY_EXCLUDE_DIR=${INPUT_TRIVY_EXCLUDE_DIR:- }
1414TRIVY_RULES=${INPUT_TRIVY_RULES:- }
1515
16+
1617# Run ESLint (JavaScript SAST) if enabled
17- if [[ " $INPUT_JAVASCRIPT_SAST_ENABLED " == " true" ]]; then
18- echo " Running ESLint"
19- ESLINT_EXCLUDE_DIR=${INPUT_ESLINT_EXCLUDE_DIR:- }
20- ESLINT_RULES=${INPUT_ESLINT_RULES:- }
21-
22- eslint_cmd=" npx eslint $GITHUB_WORKSPACE --ext .js,.jsx --format json --output-file /tmp/eslint_output.json"
23- if [[ -n " $ESLINT_EXCLUDE_DIR " ]]; then
24- eslint_cmd+=" --ignore-pattern $ESLINT_EXCLUDE_DIR "
25- fi
26- if [[ -n " $ESLINT_RULES " ]]; then
27- eslint_cmd+=" --rule \" $ESLINT_RULES \" "
28- fi
29- eval $eslint_cmd || :
18+ if [[ " ${INPUT_JAVASCRIPT_SAST_ENABLED:- false} " == " true" ]]; then
19+ echo " Running ESLint"
20+ ESLINT_EXCLUDE_DIR=${INPUT_ESLINT_EXCLUDE_DIR:- }
21+ ESLINT_RULES=${INPUT_ESLINT_RULES:- }
22+
23+ if [[ -z " $ESLINT_RULES " ]]; then
24+ echo " Using default ESLint rules"
25+ ESLINT_RULES=$( cat << 'EOF '
26+ security/detect-eval-with-expression,
27+ security/detect-non-literal-require,
28+ security/detect-non-literal-fs-filename,
29+ security/detect-buffer-noassert,
30+ security/detect-new-buffer,
31+ security/detect-unsafe-regex,
32+ security/detect-disable-mustache-escape,
33+ security/detect-no-csrf-before-method-override,
34+ security/detect-pseudoRandomBytes,
35+ security/detect-possible-timing-attacks,
36+ security/detect-bidi-characters,
37+ security/detect-child-process,
38+ security/detect-non-literal-regexp,
39+ security/detect-object-injection,
40+ @typescript-eslint/no-implied-eval,
41+ @typescript-eslint/no-throw-literal,
42+ @typescript-eslint/no-misused-promises,
43+ @typescript-eslint/no-unsafe-argument,
44+ @typescript-eslint/no-unsafe-assignment,
45+ @typescript-eslint/no-unsafe-call,
46+ @typescript-eslint/no-unsafe-member-access,
47+ @typescript-eslint/no-unsafe-return,
48+ @typescript-eslint/ban-ts-comment,
49+ @typescript-eslint/no-explicit-any,
50+ @typescript-eslint/explicit-module-boundary-types,
51+ @typescript-eslint/no-floating-promises,
52+ @typescript-eslint/no-for-in-array,
53+ @typescript-eslint/no-misused-new,
54+ @typescript-eslint/no-non-null-asserted-optional-chain,
55+ @typescript-eslint/no-non-null-assertion,
56+ @typescript-eslint/no-unnecessary-type-assertion,
57+ @typescript-eslint/prefer-optional-chain,
58+ @typescript-eslint/prefer-nullish-coalescing,
59+ @typescript-eslint/restrict-plus-operands,
60+ @typescript-eslint/restrict-template-expressions,
61+ @typescript-eslint/require-await,
62+ @typescript-eslint/unbound-method,
63+ @typescript-eslint/array-type,
64+ @typescript-eslint/ban-types,
65+ @typescript-eslint/consistent-type-assertions,
66+ @typescript-eslint/consistent-type-definitions,
67+ @typescript-eslint/explicit-function-return-type,
68+ @typescript-eslint/no-empty-interface,
69+ @typescript-eslint/no-inferrable-types,
70+ @typescript-eslint/no-invalid-void-type,
71+ @typescript-eslint/no-redeclare,
72+ @typescript-eslint/no-shadow,
73+ @typescript-eslint/no-unused-vars,
74+ @typescript-eslint/no-use-before-define,
75+ @typescript-eslint/prefer-as-const
76+ EOF
77+ )
78+ fi
79+
80+ # Convert rule list to JSON map: "rule-name": "error"
81+ ESLINT_RULES_JSON=$( echo " $ESLINT_RULES " | tr ' ,' ' \n' | sed ' /^\s*$/d' | awk ' {printf "\"%s\": \"error\",\n", $0}' | sed ' $s/,$//' )
82+
83+ if [[ ! -f " $WORKSPACE /eslint.config.mjs" ]]; then
84+ echo " Adding fallback ESLint config"
85+ cat << EOF > "$WORKSPACE /eslint.config.mjs"
86+ export default [
87+ {
88+ files: ['**/*.js', '**/*.jsx', '**/*.ts', '**/*.tsx'],
89+ rules: {
90+ $ESLINT_RULES_JSON
91+ },
92+ },
93+ ];
94+ EOF
95+ fi
96+
97+ eslint_cmd=" npx --yes eslint --config $WORKSPACE /eslint.config.mjs $WORKSPACE --ext .js,.jsx,.ts,.tsx --format json --output-file $OUTPUT_DIR /eslint_output.json"
98+
99+ if [[ -n " $ESLINT_EXCLUDE_DIR " ]]; then
100+ IFS=' ,' read -ra EXCLUDES <<< " $ESLINT_EXCLUDE_DIR"
101+ for exclude in " ${EXCLUDES[@]} " ; do
102+ eslint_cmd+=" --ignore-pattern $exclude "
103+ done
104+ fi
105+
106+ eval $eslint_cmd || :
30107fi
31108
109+
32110# Run Bandit (Python SAST) if enabled
33111if [[ " $INPUT_PYTHON_SAST_ENABLED " == " true" ]]; then
34112 echo " Running Bandit"
@@ -39,6 +117,7 @@ if [[ "$INPUT_PYTHON_SAST_ENABLED" == "true" ]]; then
39117 if [[ -n " $BANDIT_RULES " ]]; then
40118 bandit_cmd+=" --skip $BANDIT_RULES "
41119 fi
120+ echo $bandit_cmd
42121 eval $bandit_cmd || :
43122fi
44123
@@ -95,6 +174,12 @@ if [[ "$INPUT_SECRET_SCANNING_ENABLED" == "true" ]]; then
95174fi
96175
97176# Execute the custom Python script to process findings
98- cd /
177+ if [ " $LOCAL_TESTING " != " true" ]; then
178+ cd /
179+ fi
99180mv /tmp/* .json .
100- python socket_external_tools_runner.py
181+ if [ " $LOCAL_TESTING " != " true" ]; then
182+ python socket_external_tools_runner.py
183+ else
184+ python socket_external_tools_runner.py
185+ fi
0 commit comments