Skip to content

Commit 0cff76e

Browse files
Action251202 (#66)
* test stages * acorn parse error handling * parse error handle
1 parent 897c5b3 commit 0cff76e

File tree

4 files changed

+78
-54
lines changed

4 files changed

+78
-54
lines changed

analyzer/lib/actions/checkActionsHardCodedValues.js

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,20 @@ function detectHardcodedValues(code, scriptName) {
7676

7777
let processedCode = String(code || '').replace(/(?!\w+#)\b#(\w+)/g, "_$1");
7878

79-
const ast = acorn.parse(processedCode, {
80-
ecmaVersion: "latest",
81-
locations: true,
82-
});
79+
let ast;
80+
try {
81+
ast = acorn.parse(processedCode, {
82+
ecmaVersion: "latest",
83+
locations: true,
84+
});
85+
} catch (e) {
86+
if (e instanceof SyntaxError) {
87+
console.error(`[ACORN PARSE ERROR] Skipping script "${scriptName}" due to malformed code`);
88+
// Return an empty array so the main loop can continue
89+
return [];
90+
}
91+
throw e; // Re-throw other unexpected errors
92+
}
8393

8494
// Walk through the AST
8595
walk(ast, {
@@ -147,6 +157,9 @@ function checkActionsHardCodedValues(options) {
147157
);
148158
try {
149159
var report = detectHardcodedValues(action.code, actionName);
160+
if (report.length === 0) {
161+
continue;
162+
}
150163
if (report.length > 0) {
151164
reports.push({ name: actionName, report: report });
152165
}

analyzer/lib/databases/checkDASHardCodedValues.js

Lines changed: 58 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -67,59 +67,70 @@ const acorn = require("acorn");
6767
const walk = require("estree-walker").walk;
6868

6969
function detectHardcodedValues(code, scriptName) {
70-
let processedCode = code.replace(/(?!\w+#)\b#(\w+)/g, "_$1");
71-
const ast = acorn.parse(processedCode, {
70+
let processedCode = String(code || '').replace(/(?!\w+#)\b#(\w+)/g, "_$1");
71+
72+
let ast;
73+
try {
74+
ast = acorn.parse(processedCode, {
7275
ecmaVersion: "latest",
7376
locations: true,
74-
});
77+
});
78+
} catch (e) {
79+
if (e instanceof SyntaxError) {
80+
console.error(`[ACORN PARSE ERROR] Skipping script "${scriptName}" due to malformed code`);
81+
// Return an empty array so the main loop can continue
82+
return [];
83+
}
84+
throw e; // Re-throw other unexpected errors
85+
}
7586

76-
const hardcodedValues = [];
87+
const hardcodedValues = [];
7788

78-
walk(ast, {
79-
enter(node) {
80-
// Variable assignments
81-
if (node.type === "VariableDeclaration") {
82-
node.declarations.forEach((declaration) => {
83-
if (
84-
declaration.init &&
85-
declaration.init.type === "Literal" &&
86-
typeof declaration.init.value === "string" &&
87-
!isCommonException(declaration.init.value)
88-
) {
89-
hardcodedValues.push({
90-
scriptName: scriptName,
91-
variableName: declaration.id.name,
92-
field: "hard_coded_value_detected",
93-
status: CONSTANTS.FAIL,
94-
type: typeof declaration.init.value,
95-
line: declaration.loc.start.line,
96-
column: declaration.loc.start.column,
97-
});
98-
}
99-
});
100-
}
89+
walk(ast, {
90+
enter(node) {
91+
// Variable assignments
92+
if (node.type === "VariableDeclaration") {
93+
node.declarations.forEach((declaration) => {
94+
if (
95+
declaration.init &&
96+
declaration.init.type === "Literal" &&
97+
typeof declaration.init.value === "string" &&
98+
!isCommonException(declaration.init.value)
99+
) {
100+
hardcodedValues.push({
101+
scriptName: scriptName,
102+
variableName: declaration.id.name,
103+
field: "hard_coded_value_detected",
104+
status: CONSTANTS.FAIL,
105+
type: typeof declaration.init.value,
106+
line: declaration.loc.start.line,
107+
column: declaration.loc.start.column,
108+
});
109+
}
110+
});
111+
}
101112

102-
// Object literals
103-
if (
104-
node.type === "Property" &&
105-
node.value.type === "Literal" &&
106-
typeof node.value.value === "string" &&
107-
!isCommonException(node.value.value)
108-
) {
109-
hardcodedValues.push({
110-
scriptName: scriptName,
111-
variableName: node.key.name || node.key.value,
112-
field: "hard_coded_value_detected",
113-
status: CONSTANTS.FAIL,
114-
type: typeof node.value.value,
115-
line: node.loc.start.line,
116-
column: node.loc.start.column,
117-
});
118-
}
119-
},
120-
});
113+
// Object literals
114+
if (
115+
node.type === "Property" &&
116+
node.value.type === "Literal" &&
117+
typeof node.value.value === "string" &&
118+
!isCommonException(node.value.value)
119+
) {
120+
hardcodedValues.push({
121+
scriptName: scriptName,
122+
variableName: node.key.name || node.key.value,
123+
field: "hard_coded_value_detected",
124+
status: CONSTANTS.FAIL,
125+
type: typeof node.value.value,
126+
line: node.loc.start.line,
127+
column: node.loc.start.column,
128+
});
129+
}
130+
},
131+
});
121132

122-
return hardcodedValues;
133+
return hardcodedValues;
123134
}
124135

125136
// Helper functions

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@auth0/auth0-checkmate",
3-
"version": "1.6.4",
3+
"version": "1.6.5",
44
"description": "A command line tool for checking configuration of your Auth0 tenant",
55
"main": "analyzer/report.js",
66
"scripts": {

0 commit comments

Comments
 (0)