From dc25bc26b51db32938f082f92e7ed76dfd5f2998 Mon Sep 17 00:00:00 2001 From: Frederik Reiter Date: Tue, 5 Apr 2022 15:41:01 +0200 Subject: [PATCH 1/5] Fix crash on invalid host header --- api/src/routes/ical.ts | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/api/src/routes/ical.ts b/api/src/routes/ical.ts index 80bc1fb0a..a04dd079c 100644 --- a/api/src/routes/ical.ts +++ b/api/src/routes/ical.ts @@ -53,18 +53,17 @@ export function icalRoute(pool: Pool): Handler { const ctfs = await getCtfs(); for (const ctf of ctfs) { - // I'm not sure if this works in all cases (e.g. if ctfs aren't at /#/ctf/ but at /ctfnote/#/ctf/...) - const ctf_url = new URL( - `/#/ctf/${ctf.id}-${slugify(ctf.title)}/info`, - `${req.protocol}://${req.headers.host}` - ); + + const proto = req.headers["x-forwarded-proto"] || req.protocol; + const host = req.headers["x-forwarded-host"] || req.headers.host; + const ctf_url = `${proto}://${host}/#/ctf/${ctf.id}-${slugify(ctf.title)}/info`; cal.createEvent({ start: ctf.start_time, end: ctf.end_time, description: ctf.description, summary: ctf.title, - url: ctf_url.href, + url: ctf_url, }); } From f69a93a70cc564121ee6b823728e690f86af809d Mon Sep 17 00:00:00 2001 From: Frederik Reiter Date: Tue, 5 Apr 2022 16:38:50 +0200 Subject: [PATCH 2/5] Add X-Forwarded-Proto and X-Forwarded-Host to nginx config --- front/nginx.conf | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/front/nginx.conf b/front/nginx.conf index b67b12bfb..d476313aa 100644 --- a/front/nginx.conf +++ b/front/nginx.conf @@ -22,6 +22,8 @@ server { proxy_set_header Connection $http_connection; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header X-Forwarded-Proto $scheme; + proxy_set_header X-Forwarded-Host $host; add_header Pragma "no-cache"; } @@ -33,6 +35,8 @@ server { proxy_set_header Connection $http_connection; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header X-Forwarded-Proto $scheme; + proxy_set_header X-Forwarded-Host $host; add_header Pragma "no-cache"; } @@ -44,6 +48,8 @@ server { proxy_set_header Connection $http_connection; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header X-Forwarded-Proto $scheme; + proxy_set_header X-Forwarded-Host $host; add_header Pragma "no-cache"; } @@ -55,6 +61,8 @@ server { proxy_set_header Connection $http_connection; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header X-Forwarded-Proto $scheme; + proxy_set_header X-Forwarded-Host $host; add_header Pragma "no-cache"; } From e92b4211e82fc56e49e95fbb7aa569fbd47968c2 Mon Sep 17 00:00:00 2001 From: Frederik Reiter Date: Fri, 8 Apr 2022 09:05:03 +0200 Subject: [PATCH 3/5] Add /ctf/:ctfId route as an alias --- front/src/router/routes.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/front/src/router/routes.ts b/front/src/router/routes.ts index d704a9a48..dd220edff 100644 --- a/front/src/router/routes.ts +++ b/front/src/router/routes.ts @@ -35,6 +35,7 @@ const ctfsRoute: RouteRecordRaw = { const ctfRoute: RouteRecordRaw = { path: 'ctf/:ctfId(\\d+)-:ctfSlug', + alias: ['ctf/:ctfId(\\d+)'], name: 'ctf', redirect: { name: 'ctf-info' }, props: { @@ -53,7 +54,7 @@ const ctfRoute: RouteRecordRaw = { }, children: [ { - path: 'task/:taskId(\\d+)-:taskSlug', + path: 'task/:taskId(\\d+)-:taskSlug?', name: 'task', props: (route) => ({ taskId: parseInt(route.params.taskId as string) }), component: () => import('pages/Task.vue'), From 8e3ba1c2406ebe93e7dd6d41e0f6a0ed421fb441 Mon Sep 17 00:00:00 2001 From: Frederik Reiter Date: Fri, 8 Apr 2022 09:07:07 +0200 Subject: [PATCH 4/5] Make calendar links by id-only. --- api/package.json | 3 +-- api/src/routes/ical.ts | 3 +-- api/yarn.lock | 5 ----- 3 files changed, 2 insertions(+), 9 deletions(-) diff --git a/api/package.json b/api/package.json index 1df49a2f4..1b4971a3f 100644 --- a/api/package.json +++ b/api/package.json @@ -30,8 +30,7 @@ "ical-generator": "^3.2.1", "postgraphile": "^4.11.0", "postgraphile-plugin-connection-filter": "^2.1.1", - "postgres-migrations": "^5.3.0", - "slugify": "^1.6.5" + "postgres-migrations": "^5.3.0" }, "devDependencies": { "@types/express": "^4.17.11", diff --git a/api/src/routes/ical.ts b/api/src/routes/ical.ts index a04dd079c..f5a58f47e 100644 --- a/api/src/routes/ical.ts +++ b/api/src/routes/ical.ts @@ -1,7 +1,6 @@ import { ICalCalendar } from "ical-generator"; import { Request, Response, Handler } from "express"; import { Pool } from "pg"; -import slugify from "slugify"; type CtfRow = { id: number; @@ -56,7 +55,7 @@ export function icalRoute(pool: Pool): Handler { const proto = req.headers["x-forwarded-proto"] || req.protocol; const host = req.headers["x-forwarded-host"] || req.headers.host; - const ctf_url = `${proto}://${host}/#/ctf/${ctf.id}-${slugify(ctf.title)}/info`; + const ctf_url = `${proto}://${host}/#/ctf/${ctf.id}/info`; cal.createEvent({ start: ctf.start_time, diff --git a/api/yarn.lock b/api/yarn.lock index 59cba001a..6a1aaa082 100644 --- a/api/yarn.lock +++ b/api/yarn.lock @@ -2616,11 +2616,6 @@ slice-ansi@^4.0.0: astral-regex "^2.0.0" is-fullwidth-code-point "^3.0.0" -slugify@^1.6.5: - version "1.6.5" - resolved "https://registry.yarnpkg.com/slugify/-/slugify-1.6.5.tgz#c8f5c072bf2135b80703589b39a3d41451fbe8c8" - integrity sha512-8mo9bslnBO3tr5PEVFzMPIWwWnipGS0xVbYf65zxDqfNwmzYn1LpiKNrR6DlClusuvo+hDHd1zKpmfAe83NQSQ== - source-map-support@^0.5.17: version "0.5.21" resolved "https://registry.yarnpkg.com/source-map-support/-/source-map-support-0.5.21.tgz#04fe7c7f9e1ed2d662233c28cb2b35b9f63f6e4f" From 958d91022192d55d712586870a934bd3e24a758a Mon Sep 17 00:00:00 2001 From: Frederik Reiter Date: Fri, 8 Apr 2022 14:07:56 +0200 Subject: [PATCH 5/5] Make taskSlug optional --- front/src/router/routes.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/front/src/router/routes.ts b/front/src/router/routes.ts index dd220edff..577261db1 100644 --- a/front/src/router/routes.ts +++ b/front/src/router/routes.ts @@ -54,7 +54,8 @@ const ctfRoute: RouteRecordRaw = { }, children: [ { - path: 'task/:taskId(\\d+)-:taskSlug?', + path: 'task/:taskId(\\d+)-:taskSlug', + alias: ['task/:taskId(\\d+)'], name: 'task', props: (route) => ({ taskId: parseInt(route.params.taskId as string) }), component: () => import('pages/Task.vue'),