Skip to content

Commit

Permalink
fix: dont die on undefined. signed, a js dev
Browse files Browse the repository at this point in the history
  • Loading branch information
lirantal committed Nov 6, 2021
1 parent f11b0ef commit 24ff604
Showing 1 changed file with 34 additions and 30 deletions.
64 changes: 34 additions & 30 deletions src/rules/no-bidi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,37 +4,41 @@ export function noBidi(context) {
return {
onCodePathStart: function (codePath, node) {
// at the start of analyzing a code path
node.tokens.forEach((tokenObject) => {
if (
tokenObject.value &&
hasTrojanSource({ sourceText: tokenObject.value })
) {
context.report({
node: node,
data: {
text: tokenObject.value.toString("utf-8"),
},
message:
"Detected potential trojan source attack with unicode bidi introduced in this code: '{{text}}'.",
});
}
});
if (node.tokens && Array.isArray(node.tokens)) {
node.tokens.forEach((tokenObject) => {
if (
tokenObject.value &&
hasTrojanSource({ sourceText: tokenObject.value })
) {
context.report({
node: node,
data: {
text: tokenObject.value.toString("utf-8"),
},
message:
"Detected potential trojan source attack with unicode bidi introduced in this code: '{{text}}'.",
});
}
});
}

node.comments.forEach((tokenObject) => {
if (
tokenObject.value &&
hasTrojanSource({ sourceText: tokenObject.value })
) {
context.report({
node: node,
data: {
text: tokenObject.value.toString("utf-8"),
},
message:
"Detected potential trojan source attack with unicode bidi introduced in this comment: '{{text}}'.",
});
}
});
if (node.comments && Array.isArray(node.comments)) {
node.comments.forEach((tokenObject) => {
if (
tokenObject.value &&
hasTrojanSource({ sourceText: tokenObject.value })
) {
context.report({
node: node,
data: {
text: tokenObject.value.toString("utf-8"),
},
message:
"Detected potential trojan source attack with unicode bidi introduced in this comment: '{{text}}'.",
});
}
});
}
},
};
}

0 comments on commit 24ff604

Please sign in to comment.