Skip to content

Commit 87ed6cc

Browse files
committed
feat: add DISALLOWED_MIME_FOR_PASTE config
1 parent bf99c0e commit 87ed6cc

File tree

4 files changed

+19
-7
lines changed

4 files changed

+19
-7
lines changed

src/handlers/handleRead.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,12 +115,16 @@ export async function handleGet(request: Request, env: Env, ctx: ExecutionContex
115115
// check `if-modified-since`
116116
const pasteLastModifiedUnix = item.metadata.lastModifiedAtUnix
117117

118-
const inferred_mime =
118+
let inferred_mime =
119119
url.searchParams.get("mime") ||
120120
(ext && mime.getType(ext)) ||
121121
(item.metadata.filename && mime.getType(item.metadata.filename)) ||
122122
"text/plain"
123123

124+
if (env.DISALLOWED_MIME_FOR_PASTE.includes(inferred_mime)) {
125+
inferred_mime = "text/plain"
126+
}
127+
124128
const headerModifiedSince = request.headers.get("If-Modified-Since")
125129
if (headerModifiedSince) {
126130
const headerModifiedSinceUnix = Date.parse(headerModifiedSince) / 1000

test/controlHeaders.spec.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ test("mime type", async () => {
2727

2828
await testMime(url_pic, "image/jpeg;charset=UTF-8")
2929
await testMime(`${url_pic}.png`, "image/png;charset=UTF-8")
30+
31+
// test disallowed mimetypes
32+
await testMime(`${url_pic}.html`, "text/plain;charset=UTF-8")
33+
await testMime(`${url_pic}?mime=text/html`, "text/plain;charset=UTF-8")
3034
})
3135

3236
test("cache control", async () => {

worker-configuration.d.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* eslint-disable */
2-
// Generated by Wrangler by running `wrangler types --strict-vars false` (hash: 5fae5e306236e45554810cfa6e71ce54)
2+
// Generated by Wrangler by running `wrangler types --strict-vars false` (hash: 6b22c42e567b3c204913f826b6198cca)
33
// Runtime types generated with [email protected] 2025-04-24
44
declare namespace Cloudflare {
55
interface Env {
@@ -16,6 +16,7 @@ declare namespace Cloudflare {
1616
BASIC_AUTH: object;
1717
R2_THRESHOLD: string;
1818
R2_MAX_ALLOWED: string;
19+
DISALLOWED_MIME_FOR_PASTE: string[];
1920
R2: R2Bucket;
2021
ASSETS: Fetcher;
2122
}

wrangler.toml

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,12 @@ DEPLOY_URL = "https://shz.al"
4242
# url to repo, displayed in the index page
4343
REPO = "https://github.com/SharzyL/pastebin-worker"
4444

45-
# the name displayed in TOS
46-
TOS_MAINTAINER = "Sharzy"
47-
4845
# the page title displayed in index page
4946
INDEX_PAGE_TITLE = "Pastebin Worker"
5047

48+
# the name displayed in TOS
49+
TOS_MAINTAINER = "Sharzy"
50+
5151
# the email displayed in TOS
5252
TOS_MAIL = "[email protected]"
5353

@@ -67,8 +67,11 @@ MAX_EXPIRATION = "30d"
6767
# Leave empty to disable auth
6868
BASIC_AUTH = {}
6969

70-
# if file larger than this threshold, it will be stored in R2
70+
# Files larger than this threshold will be stored in R2
7171
R2_THRESHOLD = "100K"
7272

73-
# file larger than this will be denied
73+
# File larger than this will be denied
7474
R2_MAX_ALLOWED = "100M"
75+
76+
# The following mimetypes will be converted to text/plain
77+
DISALLOWED_MIME_FOR_PASTE = ["text/html"]

0 commit comments

Comments
 (0)