-
Couldn't load subscription status.
- Fork 11
chore: remove cors and implement helmet #1219
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
53d2d42
chore: change cors config to allow all origins and clean up typescrip…
bb26be6
feat: add helmet config and package
29dd9e3
chore: add updated lockfile
254e498
fix: update cookie type usage
665d4b6
chore: remove any
2bddf0a
chore: set frameguard to false and remove any's
6dff277
chore: combine cookie with csrf validation and update cookie type
7e2bcc9
chore: extend FastifyRequest to handle headers
95e3c1f
refactor: move CustomRequest to fastify.ts and update FastifyRequest …
b730e1e
fix: make cookies optional
dae9fcb
chore: use index signatures to better align with fastify type definit…
170dc8a
refactor: move fastify.ts to unraid-api types folder
e3de688
refactor: change cookie validation method name
d1b1df1
chore: remove redundant guard and throttler
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,27 +1,22 @@ | ||
| import { Injectable, Logger } from '@nestjs/common'; | ||
| import { Injectable } from '@nestjs/common'; | ||
mdatelle marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| import { PassportStrategy } from '@nestjs/passport'; | ||
|
|
||
| import { Strategy } from 'passport-custom'; | ||
|
|
||
| import type { CustomRequest } from '@app/unraid-api/types/request.js'; | ||
| import { AuthService } from '@app/unraid-api/auth/auth.service.js'; | ||
| import { FastifyRequest } from '@app/unraid-api/types/fastify.js'; | ||
mdatelle marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| const strategyName = 'user-cookie'; | ||
|
|
||
| @Injectable() | ||
| export class UserCookieStrategy extends PassportStrategy(Strategy, strategyName) { | ||
| static key = strategyName; | ||
| private readonly logger = new Logger(UserCookieStrategy.name); | ||
|
|
||
| constructor(private authService: AuthService) { | ||
| super(); | ||
| } | ||
|
|
||
| public validate = async (req: CustomRequest): Promise<any> => { | ||
| return ( | ||
| this.authService.validateCsrfToken( | ||
| req.headers['x-csrf-token'] || (req.query as { csrf_token?: string })?.csrf_token | ||
| ) && this.authService.validateCookiesCasbin(req.cookies) | ||
| ); | ||
| public validate = async (request: FastifyRequest): Promise<any> => { | ||
| return this.authService.validateCookiesWithCsrfToken(request); | ||
mdatelle marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| }; | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| import type { | ||
| FastifyInstance as BaseFastifyInstance, | ||
| FastifyReply as BaseFastifyReply, | ||
| FastifyRequest as BaseFastifyRequest, | ||
| } from 'fastify'; | ||
|
|
||
| // Common headers | ||
| export interface CommonHeaders { | ||
| 'x-api-key'?: string; | ||
| 'x-csrf-token'?: string; | ||
| 'x-unraid-api-version'?: string; | ||
| 'x-flash-guid'?: string; | ||
| } | ||
|
|
||
| // Common query parameters | ||
| export interface CommonQuery { | ||
| csrf_token?: string; | ||
| } | ||
|
|
||
| // Base types | ||
| type Headers = BaseFastifyRequest['headers'] & Partial<CommonHeaders>; | ||
| type Query = BaseFastifyRequest['query'] & Partial<CommonQuery>; | ||
| type Cookies = BaseFastifyRequest['cookies']; | ||
|
|
||
| export type FastifyRequest = BaseFastifyRequest<{ | ||
| Headers: Headers; | ||
| Querystring: Query; | ||
| }> & { | ||
| cookies?: Cookies; | ||
| }; | ||
mdatelle marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| export type FastifyInstance = BaseFastifyInstance; | ||
| export type FastifyReply = BaseFastifyReply; | ||
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.