jwt-cipher-algorithms
Ast Rule: function call
jwt-cipher-algorithms
function visit(node, filename, code) {
if (!node) return;
const name = node.functionName?.name;
const parent = node.functionName?.parent;
if (!name || !parent) return;
if (parent.value !== "jwt") return;
if (!["sign", "verify"].includes(name.value)) return;
if (node.arguments?.values && node.arguments?.values.length > 2) {
const badArg = node.arguments.values[2].value?.elements?.find(el => el.value?.value?.includes("none") || el.value?.elements?.some(el2 => el2.value.includes("none")));
if (!badArg) return;
const error = buildError(
badArg.start.line,
badArg.start.col,
badArg.end.line,
badArg.end.col,
`Do not use the "none" algorithm`,
"WARNING",
"SECURITY"
);
addError(error);
}
}
good.js
Expected test result: no error
bad.js
Expected test result: has error