Skip to content

Commit

Permalink
feat: add cid support in allowlist (#486)
Browse files Browse the repository at this point in the history
  • Loading branch information
Cafe137 authored Dec 28, 2023
1 parent 3148d26 commit 75d16df
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 11 deletions.
14 changes: 7 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
"@ethersphere/swarm-cid": "^0.1.0",
"axios": "^1.5.1",
"body-parser": "^1.20.2",
"cafe-utility": "^11.0.1",
"cafe-utility": "^13.1.0",
"express": "^4.18.1",
"prom-client": "^14.1.0",
"request-stats": "^3.0.0",
Expand Down
9 changes: 6 additions & 3 deletions src/proxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,12 +92,15 @@ async function fetchAndRespond(
})

if (options.allowlist) {
const currentCid = Strings.searchSubstring(path, x => x.length > 48 && x.startsWith('bah'))
const currentHash = Strings.searchHex(path, 64)

const isBlockedHash = currentHash && !options.allowlist.includes(currentHash)
const isBlockedCid = currentCid && !options.allowlist.includes(currentCid)

if (
currentHash &&
(response.headers['content-disposition'] || '').toLowerCase().includes('.htm') &&
!options.allowlist.includes(currentHash)
(isBlockedHash || isBlockedCid) &&
(response.headers['content-disposition'] || '').toLowerCase().includes('.htm')
) {
res.status(403).send('Forbidden')

Expand Down

0 comments on commit 75d16df

Please sign in to comment.