Skip to content

Commit d7649a9

Browse files
committed
v.1.3.0 proposal (#55)
* Add SetMaxTransacion function. (#54) * Add static casting in order to prevent compilation errors in older g++ versions. (#56) * Update version to 1.3.0
1 parent d20c997 commit d7649a9

15 files changed

+173
-16
lines changed

index.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ declare module 'datadog-iast-taint-tracking' {
3030
getMetrics(transactionId: string, telemetryVerbosity: number): Metrics;
3131
getRanges(transactionId: string, original: string): NativeTaintedRange[];
3232
removeTransaction(transactionId: string): void;
33+
setMaxTransactions(maxTransactions: number): void;
3334
concat(transactionId: string, result: string, op1: string, op2: string): string;
3435
trim(transactionId: string, result: string, thisArg: string): string;
3536
trimEnd(transactionId: string, result: string, thisArg: string): string;

index.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ try {
2727
},
2828
removeTransaction () {
2929
},
30+
setMaxTransactions () {
31+
},
3032
replace (transactionId, result) {
3133
return result
3234
},
@@ -58,6 +60,7 @@ const iastNativeMethods = {
5860
getRanges: addon.getRanges,
5961
createTransaction: addon.createTransaction,
6062
removeTransaction: addon.removeTransaction,
63+
setMaxTransactions: addon.setMaxTransactions,
6164
replace: require('./replace.js')(addon),
6265
concat: addon.concat,
6366
trim: addon.trim,

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "@datadog/native-iast-taint-tracking",
33
"home": "https://github.com/DataDog/dd-native-iast-taint-tracking-js/blob/main/README.md",
44
"repository": "[email protected]:DataDog/dd-native-iast-taint-tracking-js.git",
5-
"version": "1.2.1",
5+
"version": "1.3.0",
66
"description": "Datadog IAST tant tracking support for NodeJS",
77
"main": "index.js",
88
"scripts": {

src/api/string_methods.cc

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,12 +185,31 @@ void DeleteTransaction(const FunctionCallbackInfo<Value>& args) {
185185
RemoveTransaction(transactionId);
186186
}
187187

188+
void SetMaxTransactions(const FunctionCallbackInfo<Value>& args) {
189+
Isolate* isolate = args.GetIsolate();
190+
if (args.Length() != 1) {
191+
// Throw an Error that is passed back to JavaScript
192+
isolate->ThrowException(Exception::TypeError(
193+
String::NewFromUtf8(isolate,
194+
"Wrong number of arguments",
195+
NewStringType::kNormal).ToLocalChecked()));
196+
return;
197+
}
198+
199+
if (!args[0]->IsNumber()) {
200+
return;
201+
}
202+
203+
iast::SetMaxTransactions(args[0]->IntegerValue(isolate->GetCurrentContext()).FromJust());
204+
}
205+
188206
void StringMethods::Init(Local<Object> exports) {
189207
NODE_SET_METHOD(exports, "createTransaction", CreateTransaction);
190208
NODE_SET_METHOD(exports, "newTaintedString", NewTaintedString);
191209
NODE_SET_METHOD(exports, "isTainted", IsTainted); // TODO(julio): support several objects.
192210
NODE_SET_METHOD(exports, "getRanges", GetRanges);
193211
NODE_SET_METHOD(exports, "removeTransaction", DeleteTransaction);
212+
NODE_SET_METHOD(exports, "setMaxTransactions", SetMaxTransactions);
194213
}
195214
} // namespace api
196215
} // namespace iast

src/iast.cc

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
**/
55

66
#include <node.h>
7+
#include <cstddef>
78
#include "iast.h"
89
#include "gc/gc.h"
910
#include "container/singleton.h"
@@ -17,25 +18,29 @@
1718
#include "api/replace.h"
1819
#include "api/metrics.h"
1920

20-
using transactionManger = iast::container::Singleton<iast::TransactionManager<iast::tainted::Transaction,
21+
using transactionManager = iast::container::Singleton<iast::TransactionManager<iast::tainted::Transaction,
2122
iast::tainted::transaction_key_t>>;
2223

2324
namespace iast {
2425

2526
void RehashAllTransactions(void) {
26-
transactionManger::GetInstance().RehashAll();
27+
transactionManager::GetInstance().RehashAll();
2728
}
2829

2930
void RemoveTransaction(transaction_key_t id) {
30-
transactionManger::GetInstance().Remove(id);
31+
transactionManager::GetInstance().Remove(id);
3132
}
3233

3334
Transaction* GetTransaction(transaction_key_t id) {
34-
return transactionManger::GetInstance().Get(id);
35+
return transactionManager::GetInstance().Get(id);
3536
}
3637

3738
Transaction* NewTransaction(transaction_key_t id) {
38-
return transactionManger::GetInstance().New(id);
39+
return transactionManager::GetInstance().New(id);
40+
}
41+
42+
void SetMaxTransactions(size_t maxItems) {
43+
transactionManager::GetInstance().setMaxItems(maxItems);
3944
}
4045

4146
void Init(v8::Local<v8::Object> exports) {

src/iast.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ void RehashAllTransactions(void);
2323
void RemoveTransaction(transaction_key_t id);
2424
Transaction* GetTransaction(transaction_key_t id);
2525
Transaction* NewTransaction(transaction_key_t id);
26+
void SetMaxTransactions(size_t maxItems);
2627

2728
} // namespace iast
2829

test/cpputest/transaction_manager.cc

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,3 +122,26 @@ TEST(TransactionManager, insert_beyond_limit)
122122
iastManager.Remove(key1);
123123
iastManager.Remove(key2);
124124
}
125+
126+
TEST(TransactionManager, create_beyond_limit)
127+
{
128+
int elems = 0;
129+
TransactionManager<FakeTransaction, transaction_key_t> iastManager;
130+
elems = iastManager.getMaxItems();
131+
CHECK_EQUAL(2, elems);
132+
133+
iastManager.New(1);
134+
CHECK_EQUAL(1, iastManager.Size());
135+
136+
iastManager.New(2);
137+
CHECK_EQUAL(2, iastManager.Size());
138+
139+
CHECK_EQUAL(static_cast<FakeTransaction*>(nullptr), iastManager.New(3));
140+
141+
iastManager.setMaxItems(3);
142+
iastManager.New(3);
143+
CHECK_EQUAL(3, iastManager.Size());
144+
145+
iastManager.Clear();
146+
CHECK_EQUAL(0, iastManager.Size());
147+
}

test/js/concat.spec.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ const { TaintedUtils, taintFormattedString, formatTaintedValue } = require('./ut
66
const assert = require('assert')
77

88
describe('Plus operator', function () {
9-
const id = '1'
9+
const id = TaintedUtils.createTransaction('1')
1010

1111
afterEach(function () {
1212
TaintedUtils.removeTransaction(id)
@@ -139,7 +139,7 @@ describe('Plus operator', function () {
139139
})
140140

141141
describe('concat method', () => {
142-
const id = '1'
142+
const id = TaintedUtils.createTransaction('1')
143143

144144
afterEach(function () {
145145
TaintedUtils.removeTransaction(id)

test/js/instantiation.spec.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ describe('Addon loading', function () {
1010
assert(TaintedUtils, 'Undefined module')
1111
assert(TaintedUtils.newTaintedString, 'Undefined')
1212
assert(TaintedUtils.isTainted, 'Undefined')
13+
assert(TaintedUtils.getRanges, 'Undefined')
14+
assert(TaintedUtils.createTransaction, 'Undefined')
15+
assert(TaintedUtils.removeTransaction, 'Undefined')
16+
assert(TaintedUtils.setMaxTransactions, 'Undefined')
1317
assert(TaintedUtils.concat, 'Undefined')
1418
assert(TaintedUtils.trim, 'Undefined')
1519
assert(TaintedUtils.trimEnd, 'Undefined')

0 commit comments

Comments
 (0)