Skip to content

Commit

Permalink
Do not propagate empty strings on slice
Browse files Browse the repository at this point in the history
  • Loading branch information
CarlesDD committed Sep 26, 2023
1 parent 9f0d0cb commit 221202b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/api/slice.cc
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@ void slice(const FunctionCallbackInfo<Value>& args) {
auto vSubject = args[2];
int sliceStart = args[3]->IntegerValue(context).FromJust();

int len = v8::Local<v8::String>::Cast(vResult)->Length();
if (len == 0) {
args.GetReturnValue().Set(vResult);
return;
}

Transaction* transaction = GetTransaction(GetLocalStringPointer(args[0]));
if (transaction == nullptr) {
args.GetReturnValue().Set(vResult);
Expand Down
10 changes: 10 additions & 0 deletions test/js/slice.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,16 @@ describe('Slice', function () {
})
})

it('Check slice empty string result', function () {
let op1 = 'hello world'
op1 = TaintedUtils.newTaintedString(id, op1, 'param1', 'REQUEST')

let result = op1.slice(6, 6)
result = TaintedUtils.slice(id, result, op1, 6)

assert.equal(TaintedUtils.isTainted(id, result), false, 'Empty string is tainted')
})

it('Secure marks are inherited', () => {
let op1 = 'hello world'
op1 = TaintedUtils.newTaintedString(id, op1, 'param1', 'REQUEST')
Expand Down

0 comments on commit 221202b

Please sign in to comment.