Skip to content

Commit

Permalink
Merge pull request #1 from JesusAlexV/add-waf
Browse files Browse the repository at this point in the history
Add waf
  • Loading branch information
JesusAlexV authored May 11, 2022
2 parents f3848be + a09954c commit 16ddc65
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 0 deletions.
14 changes: 14 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"compilerOptions": {
"jsx": "react",
"jsxFactory": "h",
"checkJs": false,
"lib": [
"dom",
"dom.iterable",
"dom.asynciterable",
"deno.ns",
"deno.unstable"
]
}
}
37 changes: 37 additions & 0 deletions waf.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// @ts-nocheck

interface WafParameter {
name: string;
disallowTags?: boolean;
}

interface WafConfig {
parameters?: WafParameter[];
}

const getParam = (url, param) => {
const { searchParams: query } = new URL(url);
return query.get(param);
}

const waf: Function = (config: WafConfig) => async (ctx: any, next: any): Promise<void> => {
// Validate parameters
if (!config.parameters) {
config.parameters = [];
}
for (const parameter of config.parameters) {
let paramValue = getParam(ctx.request.url, parameter.name);
if (paramValue) {
paramValue = paramValue.toLowerCase();
if (parameter.disallowTags) {
if (paramValue.includes('<')) {
ctx.response.body = 'Web Application Firewall: Your name cannot contain HTML tags';
return;
}
}
}
}
await next();
}

export default waf;

0 comments on commit 16ddc65

Please sign in to comment.