Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Set origin based on browser origin header
  • Loading branch information
regalijan committed Oct 19, 2023
1 parent 45e05d7 commit e0f2a79
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
4 changes: 4 additions & 0 deletions functions/api/reports/submit.ts
Expand Up @@ -37,6 +37,9 @@ export async function onRequestPost(context: RequestContext) {
if (!success) return errorResponse("Captcha test failed", 403);
}

const origin = context.request.headers.get("Origin");
if (!origin) return errorResponse("No origin header", 400);

if (bypass && !(context.data.current_user?.permissions & (1 << 5)))
return errorResponse("Bypass directive cannot be used", 403);

Expand Down Expand Up @@ -178,6 +181,7 @@ export async function onRequestPost(context: RequestContext) {
`t/${fileUploadKey}`,
file.size,
fileExten,
origin,
),
);
}
Expand Down
6 changes: 2 additions & 4 deletions functions/gcloud.ts
Expand Up @@ -17,6 +17,7 @@ export async function GenerateUploadURL(
path: string,
size: number,
fileExt: string,
origin: string,
): Promise<string> {
const accessToken = await GetAccessToken(env);
const contentTypes: { [k: string]: string } = {
Expand All @@ -43,10 +44,7 @@ export async function GenerateUploadURL(
{
headers: {
authorization: `Bearer ${accessToken}`,
origin:
typeof env.LOCAL === "undefined"
? "https://carcrushers.cc"
: "http://localhost:8788",
origin,
"x-upload-content-type": contentTypes[fileExt],
"x-upload-content-length": size.toString(),
},
Expand Down

0 comments on commit e0f2a79

Please sign in to comment.