-
Notifications
You must be signed in to change notification settings - Fork 0
/
StackInfo.js
153 lines (137 loc) · 4.16 KB
/
StackInfo.js
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
//IASTIGNORE
/*
* ****************************************************
* Licensed Materials - Property of HCL.
* (c) Copyright HCL Technologies Ltd. 2017, 2024.
* Note to U.S. Government Users *Restricted Rights.
* ****************************************************
*/
'use strict'
const Utils = require('./Utils/Utils');
const {ConfigInfo} = require("./ConfigFile/ConfigInfo");
const TaintTracker = require("./TaintTracker");
const StackTraceUtils = require("./Utils/StackTraceUtils");
const maxParamLength = 300;
class StackInfo {
constructor(type, parameters, vulnerability, rawStack) {
this.type = type
if (vulnerability != null) {
this.from_vulnerability = vulnerability
}
this.parameters = parameters
this['method-signature'] = parameters.methodSignature
this.location = 0
this.rawStack = rawStack.stack
this.stack = null
}
updateHash(vulnerability) {
const hash = Utils.createHashObject()
hash.update(this.type)
if (this['method-signature'] != null) {
hash.update(this['method-signature'])
}
if (this.stack != null) {
for (const item of this.stack) {
hash.update(item)
}
}
if (vulnerability != null) {
hash.update(vulnerability)
}
return hash.produce()
}
static getSimpleParamsStringArray (that, methodDescriptor, args, ret) {
return {
that: this.asString(that),
ret: this.asString(ret),
methodSignature: this.asString(methodDescriptor),
methodArguments: (args == null) ? [] : Array.from(args, item => this.asString(item))
}
}
static getParamsStringArray (that, methodDescriptor, args, ret) {
const res = this.getSimpleParamsStringArray(that, methodDescriptor, args, ret)
res.objects = {
that: that,
ret : ret,
args : args
}
return res
}
static getParamsStringArrayPostHook (that, methodDescriptor, args, ret) {
let res = StackInfo.getParamsStringArray(that, methodDescriptor, args, ret)
StackInfo.replacePasswordParams(res)
return res
}
static replacePasswordParams(params){
const objects = params.objects
if (ConfigInfo.ConfigInfo.hidePasswords) {
if (objects.that != null) {
StackInfo.replacePasswordValue(params, "that", objects.that);
}
if (objects.ret != null) {
StackInfo.replacePasswordValue(params, "ret", objects.ret);
}
if (objects.args != null) {
for (let i = 0; i < objects.args.length; i++) {
if (objects.args[i] != null){
StackInfo.replacePasswordValue(params, "methodArguments", objects.args[i], i);
}
}
}
}
}
static replacePasswordValue(params, key, obj, index = undefined) {
let taintData = TaintTracker.getTaintedData(obj)
if (taintData != null) {
for (const flow of taintData.flows) {
if (flow.entity.isPassword) {
if (index == null) {
params[key] = Utils.PASSWORD_TEXT
}
else {
params[key][index] = Utils.PASSWORD_TEXT
}
return
}
}
}
}
static asString(obj) {
let result = ''
if (typeof obj === 'string' || obj instanceof String) {
result = obj
}
else {
try {
result = JSON.origStringify(obj)
} catch (err) {
console.log(err)
console.log(obj)
}
}
if (result == null || result.length <= maxParamLength)
return result
return result.origSubstring(0, maxParamLength) + '...'
}
updateStack() {
if (this.stack == null) {
this.stack = StackTraceUtils.getStackTraceArray(this.rawStack);
}
if (this.parameters !== undefined){
this.object = this.parameters.that
this.arguments = this.parameters.methodArguments
this.return = this.parameters.ret
delete this.parameters
}
}
getStackTraceString() {
if (this.stack == null) {
this.updateStack()
}
return this.stack.toString()
}
setStackArray(stackArray) {
this.stack = stackArray;
}
}
module.exports = StackInfo