add optional env variable to protect the public report creation endpoint with a secret
	
		
			
	
		
	
	
		
	
		
			All checks were successful
		
		
	
	
		
			
				
	
				delpoy / build-and-deploy (push) Successful in 45s
				
			
		
		
	
	
				
					
				
			
		
			All checks were successful
		
		
	
	delpoy / build-and-deploy (push) Successful in 45s
				
			This commit is contained in:
		| @@ -1,5 +1,6 @@ | |||||||
| DATABASE_URI=sqlite://./database.db | DATABASE_URI=sqlite://./database.db | ||||||
| ADMIN_USER=admin | ADMIN_USER=admin | ||||||
| ADMIN_PASSWORD=admin | ADMIN_PASSWORD=admin | ||||||
|  | REPORT_SECRET= | ||||||
| PUBLIC_START_DATE=2023-12-26T00:00:00+0200 | PUBLIC_START_DATE=2023-12-26T00:00:00+0200 | ||||||
| PUBLIC_BASE_PATH= | PUBLIC_BASE_PATH= | ||||||
|   | |||||||
| @@ -30,11 +30,12 @@ $ node -r dotenv/config build/index.js | |||||||
| Configurations can be done with env variables | Configurations can be done with env variables | ||||||
|  |  | ||||||
| | Name                | Description                                                                                                                                                                  | | | Name                | Description                                                                                                                                                                  | | ||||||
| | ------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------- | | | ------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | ||||||
| | `HOST`              | Host the server should listen on                                                                                                                                             | | | `HOST`              | Host the server should listen on                                                                                                                                             | | ||||||
| | `PORT`              | Port the server should listen on                                                                                                                                             | | | `PORT`              | Port the server should listen on                                                                                                                                             | | ||||||
| | `DATABASE_URI`      | URI to the database as a connection string. Supported databases are [sqlite](https://www.sqlite.org/index.html) and [mariadb](https://mariadb.org/)                          | | | `DATABASE_URI`      | URI to the database as a connection string. Supported databases are [sqlite](https://www.sqlite.org/index.html) and [mariadb](https://mariadb.org/)                          | | ||||||
| | `ADMIN_USER`        | Name for the root admin user. The admin user won't be available if `ADMIN_USER` or `ADMIN_PASSWORD` is set                                                                   | | | `ADMIN_USER`        | Name for the root admin user. The admin user won't be available if `ADMIN_USER` or `ADMIN_PASSWORD` is set                                                                   | | ||||||
| | `ADMIN_PASSWORD`    | Password for the root admin user defined via `ADMIN_USER`. The admin user won't be available if `ADMIN_USER` or `ADMIN_PASSWORD` is set                                      | | | `ADMIN_PASSWORD`    | Password for the root admin user defined via `ADMIN_USER`. The admin user won't be available if `ADMIN_USER` or `ADMIN_PASSWORD` is set                                      | | ||||||
|  | | `REPORT_SECRET`     | Secret which may be required (as `?secret=<secret>` query parameter) to create reports on the public endpoint. Isn't required to be in the request if this variable is empty | | ||||||
| | `PUBLIC_BASE_PATH`  | If running the website on a sub-path, set this variable to the path so that assets etc. can find the correct location                                                        | | | `PUBLIC_BASE_PATH`  | If running the website on a sub-path, set this variable to the path so that assets etc. can find the correct location                                                        | | ||||||
| | `PUBLIC_START_DATE` | The start date when the event starts                                                                                                                                         | | | `PUBLIC_START_DATE` | The start date when the event starts                                                                                                                                         | | ||||||
|   | |||||||
| @@ -1,9 +1,12 @@ | |||||||
| import type { RequestHandler } from '@sveltejs/kit'; | import type { RequestHandler } from '@sveltejs/kit'; | ||||||
| import { Report, User } from '$lib/server/database'; | import { Report, User } from '$lib/server/database'; | ||||||
| import * as crypto from 'crypto'; | import * as crypto from 'crypto'; | ||||||
| import { env } from '$env/dynamic/public'; | import { env } from '$env/dynamic/private'; | ||||||
|  |  | ||||||
| export const POST = (async ({ request, url }) => { | export const POST = (async ({ request, url }) => { | ||||||
|  | 	if (env.REPORT_SECRET && url.searchParams.get('secret') !== env.REPORT_SECRET) | ||||||
|  | 		return new Response(null, { status: 401 }); | ||||||
|  |  | ||||||
| 	const data: { reporter: string; reported: string; reason: string } = await request.json(); | 	const data: { reporter: string; reported: string; reason: string } = await request.json(); | ||||||
|  |  | ||||||
| 	if (data.reporter == null || data.reported == null || data.reason == null) | 	if (data.reporter == null || data.reported == null || data.reason == null) | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user