Skip to content

Commit fe672fe

Browse files
committed
validate request headers
1 parent d560b75 commit fe672fe

File tree

3 files changed

+14
-0
lines changed

3 files changed

+14
-0
lines changed

src/components/SuggestionForm.svelte

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
const res = await fetch('/api/issue', {
3434
method: 'POST',
3535
body: JSON.stringify({ title, body, url: page.url.href, name }),
36+
headers: { 'Content-Type': 'application/json' },
3637
})
3738
3839
const res_json = await res.json()

src/routes/api/issue/+server.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,10 @@ import {
1010
GITHUB_REPO,
1111
TITLE_MAX_LENGTH,
1212
NAME_MAX_LENGTH,
13+
ORIGIN,
1314
} from './config'
1415
import { flag_violation, is_blocked, has_profanity, rate_limit } from '$lib/server/redis'
16+
import { dev } from '$app/environment'
1517

1618
const app = new App({
1719
appId: GITHUB_APP_ID,
@@ -72,6 +74,16 @@ async function parse_data(
7274
): Promise<
7375
{ error: string } | { title: string; body: string; url: string; name: string }
7476
> {
77+
const content_type = request.headers.get('Content-Type')
78+
if (content_type !== 'application/json') {
79+
return { error: 'Forbidden' }
80+
}
81+
82+
const origin = request.headers.get('origin')
83+
if (!dev && origin !== ORIGIN) {
84+
return { error: 'Forbidden' }
85+
}
86+
7587
let data
7688
try {
7789
data = await request.json()

src/routes/api/issue/config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@ export const GITHUB_REPO = 'CatDat'
55
export const TITLE_MAX_LENGTH = 50
66
export const BODY_MAX_LENGTH = 10000
77
export const NAME_MAX_LENGTH = 50
8+
export const ORIGIN = 'https://catdat.app'

0 commit comments

Comments
 (0)