Skip to content

Commit

Permalink
block bad bins
Browse files Browse the repository at this point in the history
  • Loading branch information
ntotten committed Oct 1, 2024
1 parent 4249f2c commit fdd4fce
Show file tree
Hide file tree
Showing 6 changed files with 1,655 additions and 1,044 deletions.
8 changes: 8 additions & 0 deletions config/policies.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,14 @@
},
"name": "log-request",
"policyType": "custom-code-inbound"
},
{
"handler": {
"export": "default",
"module": "$import(./modules/blocked)"
},
"name": "block-bad-bins",
"policyType": "custom-code-inbound"
}
]
}
13 changes: 9 additions & 4 deletions config/routes.oas.json
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@
"options": {}
},
"policies": {
"inbound": ["rate-limit-inbound"]
"inbound": ["block-bad-bins", "rate-limit-inbound"]
}
},
"operationId": "2ae802d2-c8e1-40ba-ac2e-f45a9b4eafab"
Expand All @@ -107,7 +107,7 @@
"options": {}
},
"policies": {
"inbound": ["rate-limit-inbound"]
"inbound": ["block-bad-bins", "rate-limit-inbound"]
}
},
"responses": {
Expand Down Expand Up @@ -147,7 +147,7 @@
"options": {}
},
"policies": {
"inbound": ["rate-limit-inbound"]
"inbound": ["block-bad-bins", "rate-limit-inbound"]
}
},
"responses": {
Expand Down Expand Up @@ -186,7 +186,12 @@
"options": {}
},
"policies": {
"inbound": ["caching-inbound", "rate-limit-inbound", "log-request"]
"inbound": [
"block-bad-bins",
"caching-inbound",
"rate-limit-inbound",
"log-request"
]
}
},
"operationId": "d1ef63f4-d081-46d4-ada2-b27e8ec5e24e"
Expand Down
21 changes: 21 additions & 0 deletions modules/blocked.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { HttpProblems, ZuploContext, ZuploRequest } from "@zuplo/runtime";
import { getBinFromUrl } from "./utils";

const BLOCKED_BINS = ["d99caaa8ed794063a917411904c65e87"];

export default async function (request: ZuploRequest, context: ZuploContext) {
const url = new URL(request.url);
const urlInfo = getBinFromUrl(url);
if (!urlInfo) {
return HttpProblems.badRequest(request, context, {
detail: "No binId specified in request",
});
}
const { binId } = urlInfo;

if (BLOCKED_BINS.includes(binId)) {
return HttpProblems.forbidden(request, context, {
detail: "This bin is blocked due to abuse.",
});
}
}
Loading

0 comments on commit fdd4fce

Please sign in to comment.