Skip to content

Commit 5c414d6

Browse files
feat(analye-wasm, redact-wasm): ignore dashes in card numbers (#5210)
This generates new WebAssembly into `@arcjet/analyze-wasm` and `@arcjet/redact-wasm` which supports this feature. This also adds tests for card numbers to make it visible and trackable what is and is supported in `@arcjet/analyze-wasm` and `@arcjet/redact-wasm`. Closes GH-5209.
1 parent c4e506a commit 5c414d6

8 files changed

+401
-0
lines changed

analyze-wasm/test/index.test.ts

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,44 @@
11
import assert from "node:assert/strict";
22
import test from "node:test";
3+
import { initializeWasm } from "../index.js";
4+
5+
const wasm = await initializeWasm({
6+
"arcjet:js-req/bot-identifier": {
7+
detect() {
8+
return [];
9+
},
10+
},
11+
"arcjet:js-req/email-validator-overrides": {
12+
hasGravatar() {
13+
return "unknown";
14+
},
15+
hasMxRecords() {
16+
return "unknown";
17+
},
18+
isDisposableEmail() {
19+
return "unknown";
20+
},
21+
isFreeEmail() {
22+
return "unknown";
23+
},
24+
},
25+
"arcjet:js-req/filter-overrides": {
26+
ipLookup() {
27+
return undefined;
28+
},
29+
},
30+
"arcjet:js-req/sensitive-information-identifier": {
31+
detect() {
32+
return [];
33+
},
34+
},
35+
"arcjet:js-req/verify-bot": {
36+
verify() {
37+
return "unverifiable";
38+
},
39+
},
40+
});
41+
assert.ok(wasm);
342

443
test("@arcjet/analyze-wasm", async function (t) {
544
await t.test("should expose the public api", async function () {
@@ -8,3 +47,77 @@ test("@arcjet/analyze-wasm", async function (t) {
847
]);
948
});
1049
});
50+
51+
test("`detectSensitiveInfo`", async function (t) {
52+
await t.test("should detect a card number", async function () {
53+
assert.deepEqual(
54+
wasm.detectSensitiveInfo("a 4242424242424242 b", {
55+
entities: { tag: "allow", val: [] },
56+
skipCustomDetect: false,
57+
}),
58+
{
59+
allowed: [],
60+
denied: [
61+
{ end: 18, identifiedType: { tag: "credit-card-number" }, start: 2 },
62+
],
63+
},
64+
);
65+
});
66+
67+
await t.test("should detect a card number if in `allow`", async function () {
68+
assert.deepEqual(
69+
wasm.detectSensitiveInfo("a 4242424242424242 b", {
70+
entities: { tag: "allow", val: [{ tag: "credit-card-number" }] },
71+
skipCustomDetect: false,
72+
}),
73+
{
74+
allowed: [
75+
{
76+
end: 18,
77+
identifiedType: { tag: "credit-card-number" },
78+
start: 2,
79+
},
80+
],
81+
denied: [],
82+
},
83+
);
84+
});
85+
86+
await t.test("should detect a card number w/ dashes", async function () {
87+
assert.deepEqual(
88+
wasm.detectSensitiveInfo("a 4242-4242-4242-4242 b", {
89+
entities: { tag: "allow", val: [{ tag: "credit-card-number" }] },
90+
skipCustomDetect: false,
91+
}),
92+
{
93+
allowed: [
94+
{
95+
end: 21,
96+
identifiedType: { tag: "credit-card-number" },
97+
start: 2,
98+
},
99+
],
100+
denied: [],
101+
},
102+
);
103+
});
104+
105+
await t.test("should detect a card number w/ spaces", async function () {
106+
assert.deepEqual(
107+
wasm.detectSensitiveInfo("a 4242 4242 4242 4242 b", {
108+
entities: { tag: "allow", val: [{ tag: "credit-card-number" }] },
109+
skipCustomDetect: false,
110+
}),
111+
{
112+
allowed: [
113+
{
114+
end: 21,
115+
identifiedType: { tag: "credit-card-number" },
116+
start: 2,
117+
},
118+
],
119+
denied: [],
120+
},
121+
);
122+
});
123+
});
2.44 KB
Binary file not shown.
2.44 KB
Binary file not shown.

0 commit comments

Comments
 (0)