Skip to content

Commit b62c2d4

Browse files
author
Arun Patra
authored
Merge pull request #12 from Reloadly/enable-user-specified-block-lists
Enable user specified block lists.
2 parents 19cd3e3 + b2197f1 commit b62c2d4

5 files changed

Lines changed: 40 additions & 1 deletion

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,4 @@ node_modules/
2626
*.tgz
2727

2828
lib
29+
*.iml

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@prizemates/http-firewall",
3-
"version": "1.0.2",
3+
"version": "1.0.3",
44
"description": "HTTP Firewall based on Spring Security HttpFirewall",
55
"private": false,
66
"main": "./lib/index.js",

src/__tests__/strict-http-firewall.tests.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,24 @@ describe('HttpStrictFirewall test suite', () => {
147147
expect(res.statusCode).toBe(403);
148148
});
149149

150+
it('Should reject request when user provided decoded url block list is provided', async () => {
151+
const app = express();
152+
153+
const options: HttpFirewallOptions = {decodedUrlBlockList : ['.exe', '.pl']};
154+
app.use(httpFirewall(options));
155+
const res = await request(app).get('/test/some-file.exe').set('Content-Type', 'application/json');
156+
expect(res.statusCode).toBe(403);
157+
});
158+
159+
it('Should reject request when user provided encoded url block list is provided', async () => {
160+
const app = express();
161+
162+
const options: HttpFirewallOptions = {encodedUrlBlockList : ['.exe', '.pl']};
163+
app.use(httpFirewall(options));
164+
const res = await request(app).get('/test/some-file.exe').set('Content-Type', 'application/json');
165+
expect(res.statusCode).toBe(403);
166+
});
167+
150168
it('Should allow encoded period when permitted', async () => {
151169
const app = express();
152170

src/strict-http-firewall.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,14 @@ class StrictHttpFirewall {
139139
if (options.allowedHostnames !== undefined) {
140140
this.allowedHostnames = options.allowedHostnames;
141141
}
142+
143+
if (options.decodedUrlBlockList !== undefined && options.decodedUrlBlockList.length !== 0) {
144+
this.decodedUrlBlocklist.push(... options.decodedUrlBlockList);
145+
}
146+
147+
if (options.encodedUrlBlockList !== undefined && options.encodedUrlBlockList.length !== 0) {
148+
this.encodedUrlBlocklist.push(... options.encodedUrlBlockList);
149+
}
142150
}
143151
}
144152

src/types/firewall.models.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,4 +231,16 @@ export interface HttpFirewallOptions {
231231
* Default is false
232232
*/
233233
logToConsole?: boolean;
234+
235+
/**
236+
* A list of strings that are considered malicious in URLs. If these strings are found in the request URL, the
237+
* request will be rejected.
238+
*/
239+
decodedUrlBlockList?: string[];
240+
241+
/**
242+
* A list of strings that are considered malicious in encoded URLs. If these strings are found in the request URL, the
243+
* request will be rejected.
244+
*/
245+
encodedUrlBlockList?: string[];
234246
}

0 commit comments

Comments
 (0)