-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathno-timing-attacks.js
More file actions
57 lines (47 loc) · 1.55 KB
/
Copy pathno-timing-attacks.js
File metadata and controls
57 lines (47 loc) · 1.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
/**
* Looks for potential hot spot string comparisons
* @author Adam Baldwin
*/
//------------------------------------------------------------------------------
// Rule Definition
//------------------------------------------------------------------------------
var keywords = '((' + [
'password',
'secret',
'api',
'token',
'auth',
'pass',
'hash'
].join(')|(') + '))';
var re = new RegExp('^' + keywords + '$', 'im');
function containsKeyword (node) {
if (node.type === 'Identifier') {
if (re.test(node.name))
return true;
}
return
}
module.exports = function(context) {
"use strict";
return {
"IfStatement": function(node) {
if (node.test && node.test.type === 'BinaryExpression') {
if (node.test.operator === '==' || node.test.operator === '===' || node.test.operator === '!=' || node.test.operator === '!==') {
if (node.test.left) {
var left = containsKeyword(node.test.left);
if (left) {
return context.report(node, "Potential timing attack, left side: " + left);
}
}
if (node.test.right) {
var right = containsKeyword(node.test.right);
if (right) {
return context.report(node, "Potential timing attack, right side: " + right);
}
}
}
}
}
};
};