Skip to content

Commit 768162e

Browse files
Merge pull request #551 from AikidoSec/js-injection
Return early if user input is 2 chars or shorter
2 parents 1a00350 + 431a8b5 commit 768162e

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import * as t from "tap";
2+
import { shouldReturnEarly } from "./shouldReturnEarly";
3+
4+
t.test("it returns true if code is shorter than user input", async (t) => {
5+
t.same(true, shouldReturnEarly("code", "user input code"));
6+
});
7+
8+
t.test("it returns true if code not user input", async (t) => {
9+
t.same(true, shouldReturnEarly("code code code", "user input"));
10+
});
11+
12+
t.test("it returns true if shorter than 3 chars", async (t) => {
13+
t.same(true, shouldReturnEarly("a(", "a("));
14+
});
15+
16+
t.test("it returns true if alphanumeric", async (t) => {
17+
t.same(true, shouldReturnEarly("abc123_", "abc123_"));
18+
});
19+
20+
t.test("it returns true if comma separated list of numbers", async (t) => {
21+
t.same(true, shouldReturnEarly("1,2,3", "1,2,3"));
22+
t.same(true, shouldReturnEarly("1, 2, 3", "1, 2, 3"));
23+
});
24+
25+
t.test("it returns false if code inside user input", async (t) => {
26+
t.same(false, shouldReturnEarly("a()", "a()"));
27+
});

library/vulnerabilities/js-injection/shouldReturnEarly.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
export function shouldReturnEarly(code: string, userInput: string) {
22
// User input too small or larger than query
3-
if (userInput.length <= 1 || code.length < userInput.length) {
3+
if (userInput.length <= 2 || code.length < userInput.length) {
44
return true;
55
}
66

0 commit comments

Comments
 (0)