detect-buffer-noassert
Ast Rule: function call
detect-buffer-noassert
const read = [
'readUInt8',
'readUInt16LE',
'readUInt16BE',
'readUInt32LE',
'readUInt32BE',
'readInt8',
'readInt16LE',
'readInt16BE',
'readInt32LE',
'readInt32BE',
'readFloatLE',
'readFloatBE',
'readDoubleLE',
'readDoubleBE',
];
const write = [
'writeUInt8',
'writeUInt16LE',
'writeUInt16BE',
'writeUInt32LE',
'writeUInt32BE',
'writeInt8',
'writeInt16LE',
'writeInt16BE',
'writeInt32LE',
'writeInt32BE',
'writeFloatLE',
'writeFloatBE',
'writeDoubleLE',
'writeDoubleBE',
];
function visit(node, filename, code) {
let index;
if (read.includes(node?.functionName?.name?.value)) {
index = 0;
} else if (write.includes(node?.functionName?.name?.value)) {
index = 1;
}
if (index !== "undefined") {
const argument = node.arguments?.values[index];
if (argument.value.value === "true") {
addError(buildError(
node.start.line,
node.start.col,
node.end.line,
node.end.col,
`Found Buffer with noAssert flag set true`,
"WARNING",
"SECURITY",
));
}
}
}
bad.js
Expected test result: has error
good.js
Expected test result: no error