Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 17 additions & 4 deletions analyzer/lib/actions/checkActionsHardCodedValues.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,20 @@ function detectHardcodedValues(code, scriptName) {

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

const ast = acorn.parse(processedCode, {
ecmaVersion: "latest",
locations: true,
});
let ast;
try {
ast = acorn.parse(processedCode, {
ecmaVersion: "latest",
locations: true,
});
} catch (e) {
if (e instanceof SyntaxError) {
console.error(`[ACORN PARSE ERROR] Skipping script "${scriptName}" due to malformed code`);
// Return an empty array so the main loop can continue
return [];
}
throw e; // Re-throw other unexpected errors
}

// Walk through the AST
walk(ast, {
Expand Down Expand Up @@ -147,6 +157,9 @@ function checkActionsHardCodedValues(options) {
);
try {
var report = detectHardcodedValues(action.code, actionName);
if (report.length === 0) {
continue;
}
if (report.length > 0) {
reports.push({ name: actionName, report: report });
}
Expand Down
105 changes: 58 additions & 47 deletions analyzer/lib/databases/checkDASHardCodedValues.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,59 +67,70 @@ const acorn = require("acorn");
const walk = require("estree-walker").walk;

function detectHardcodedValues(code, scriptName) {
let processedCode = code.replace(/(?!\w+#)\b#(\w+)/g, "_$1");
const ast = acorn.parse(processedCode, {
let processedCode = String(code || '').replace(/(?!\w+#)\b#(\w+)/g, "_$1");

let ast;
try {
ast = acorn.parse(processedCode, {
ecmaVersion: "latest",
locations: true,
});
});
} catch (e) {
if (e instanceof SyntaxError) {
console.error(`[ACORN PARSE ERROR] Skipping script "${scriptName}" due to malformed code`);
// Return an empty array so the main loop can continue
return [];
}
throw e; // Re-throw other unexpected errors
}

const hardcodedValues = [];
const hardcodedValues = [];

walk(ast, {
enter(node) {
// Variable assignments
if (node.type === "VariableDeclaration") {
node.declarations.forEach((declaration) => {
if (
declaration.init &&
declaration.init.type === "Literal" &&
typeof declaration.init.value === "string" &&
!isCommonException(declaration.init.value)
) {
hardcodedValues.push({
scriptName: scriptName,
variableName: declaration.id.name,
field: "hard_coded_value_detected",
status: CONSTANTS.FAIL,
type: typeof declaration.init.value,
line: declaration.loc.start.line,
column: declaration.loc.start.column,
});
}
});
}
walk(ast, {
enter(node) {
// Variable assignments
if (node.type === "VariableDeclaration") {
node.declarations.forEach((declaration) => {
if (
declaration.init &&
declaration.init.type === "Literal" &&
typeof declaration.init.value === "string" &&
!isCommonException(declaration.init.value)
) {
hardcodedValues.push({
scriptName: scriptName,
variableName: declaration.id.name,
field: "hard_coded_value_detected",
status: CONSTANTS.FAIL,
type: typeof declaration.init.value,
line: declaration.loc.start.line,
column: declaration.loc.start.column,
});
}
});
}

// Object literals
if (
node.type === "Property" &&
node.value.type === "Literal" &&
typeof node.value.value === "string" &&
!isCommonException(node.value.value)
) {
hardcodedValues.push({
scriptName: scriptName,
variableName: node.key.name || node.key.value,
field: "hard_coded_value_detected",
status: CONSTANTS.FAIL,
type: typeof node.value.value,
line: node.loc.start.line,
column: node.loc.start.column,
});
}
},
});
// Object literals
if (
node.type === "Property" &&
node.value.type === "Literal" &&
typeof node.value.value === "string" &&
!isCommonException(node.value.value)
) {
hardcodedValues.push({
scriptName: scriptName,
variableName: node.key.name || node.key.value,
field: "hard_coded_value_detected",
status: CONSTANTS.FAIL,
type: typeof node.value.value,
line: node.loc.start.line,
column: node.loc.start.column,
});
}
},
});

return hardcodedValues;
return hardcodedValues;
}

// Helper functions
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@auth0/auth0-checkmate",
"version": "1.6.4",
"version": "1.6.5",
"description": "A command line tool for checking configuration of your Auth0 tenant",
"main": "analyzer/report.js",
"scripts": {
Expand Down