File tree Expand file tree Collapse file tree 4 files changed +37
-2
lines changed Expand file tree Collapse file tree 4 files changed +37
-2
lines changed Original file line number Diff line number Diff line change @@ -60,6 +60,9 @@ import { QueueModule } from '@queue/queue.module';
60
60
configService . getOrThrow < string > ( 'SWAGGER_PATH' ) ,
61
61
configService . getOrThrow < string > ( 'SCALAR_PATH' ) ,
62
62
] ,
63
+ serveStaticOptions : {
64
+ dotfiles : 'deny' ,
65
+ } ,
63
66
} ,
64
67
] ,
65
68
} ) ,
Original file line number Diff line number Diff line change 1
1
export * from './basic-auth.middleware' ;
2
2
export * from './get-real-ip' ;
3
+ export * from './proxy-check.middleware' ;
Original file line number Diff line number Diff line change
1
+ import { NextFunction , Request , Response } from 'express' ;
2
+
3
+ import { Logger } from '@nestjs/common' ;
4
+
5
+ import { isDevelopment } from '@common/utils/startup-app' ;
6
+
7
+ const logger = new Logger ( 'ProxyCheckMiddleware' ) ;
8
+
9
+ export function proxyCheckMiddleware ( req : Request , res : Response , next : NextFunction ) {
10
+ if ( isDevelopment ( ) ) {
11
+ return next ( ) ;
12
+ }
13
+
14
+ const isProxy = Boolean ( req . headers [ 'x-forwarded-for' ] ) ;
15
+ const isHttps = Boolean ( req . headers [ 'x-forwarded-proto' ] === 'https' ) ;
16
+
17
+ logger . debug (
18
+ `X-Forwarded-For: ${ req . headers [ 'x-forwarded-for' ] } , X-Forwarded-Proto: ${ req . headers [ 'x-forwarded-proto' ] } ` ,
19
+ ) ;
20
+
21
+ if ( ! isHttps || ! isProxy ) {
22
+ res . socket ?. destroy ( ) ;
23
+ logger . error ( 'Reverse proxy and HTTPS are required.' ) ;
24
+ return false ;
25
+ }
26
+
27
+ return next ( ) ;
28
+ }
Original file line number Diff line number Diff line change @@ -13,9 +13,10 @@ import { ConfigService } from '@nestjs/config';
13
13
import { NestFactory } from '@nestjs/core' ;
14
14
15
15
import { getDocs , isDevelopment , isProduction } from '@common/utils/startup-app' ;
16
- import { ProxyCheckGuard } from '@common/guards/proxy-check/proxy-check.guard' ;
16
+ // import { ProxyCheckGuard } from '@common/guards/proxy-check/proxy-check.guard';
17
17
import { getStartMessage } from '@common/utils/startup-app/get-start-message' ;
18
18
import { getRealIp } from '@common/middlewares/get-real-ip' ;
19
+ import { proxyCheckMiddleware } from '@common/middlewares' ;
19
20
import { AxiosService } from '@common/axios' ;
20
21
21
22
import { AppModule } from './app.module' ;
@@ -106,6 +107,8 @@ async function bootstrap(): Promise<void> {
106
107
107
108
app . setGlobalPrefix ( ROOT ) ;
108
109
110
+ app . use ( proxyCheckMiddleware ) ;
111
+
109
112
await getDocs ( app , config ) ;
110
113
111
114
app . enableCors ( {
@@ -116,7 +119,7 @@ async function bootstrap(): Promise<void> {
116
119
117
120
app . useGlobalPipes ( new ZodValidationPipe ( ) ) ;
118
121
119
- app . useGlobalGuards ( new ProxyCheckGuard ( { exclude : [ ] } ) ) ;
122
+ // app.useGlobalGuards(new ProxyCheckGuard({ exclude: [] }));
120
123
121
124
app . enableShutdownHooks ( ) ;
122
125
You can’t perform that action at this time.
0 commit comments