5
5
import { ServeStaticModule } from '@nestjs/serve-static' ;
6
6
import { RouterModule } from '@nestjs/core' ;
7
7
import { join } from 'path' ;
8
+ import { Response } from 'express' ;
8
9
import config , { Config } from 'src/utils/config' ;
9
10
import { PluginModule } from 'src/modules/plugin/plugin.module' ;
10
11
import { CommandsModule } from 'src/modules/commands/commands.module' ;
@@ -33,11 +34,16 @@ import { CliModule } from './modules/cli/cli.module';
33
34
import { StaticsManagementModule } from './modules/statics-management/statics-management.module' ;
34
35
import { ExcludeRouteMiddleware } from './middleware/exclude-route.middleware' ;
35
36
import SubpathProxyMiddleware from './middleware/subpath-proxy.middleware' ;
37
+ import XFrameOptionsMiddleware from './middleware/x-frame-options.middleware' ;
36
38
import { routes } from './app.routes' ;
37
39
38
40
const SERVER_CONFIG = config . get ( 'server' ) as Config [ 'server' ] ;
39
41
const PATH_CONFIG = config . get ( 'dir_path' ) as Config [ 'dir_path' ] ;
40
42
43
+ const setXFrameOptionsHeader = ( res : Response ) => {
44
+ res . setHeader ( 'X-Frame-Options' , 'SAMEORIGIN' ) ;
45
+ } ;
46
+
41
47
@Module ( {
42
48
imports : [
43
49
LocalDatabaseModule ,
@@ -73,6 +79,7 @@ const PATH_CONFIG = config.get('dir_path') as Config['dir_path'];
73
79
serveRoot : SERVER_CONFIG . proxyPath ? `/${ SERVER_CONFIG . proxyPath } ` : '' ,
74
80
serveStaticOptions : {
75
81
index : false ,
82
+ setHeaders : setXFrameOptionsHeader ,
76
83
} ,
77
84
} ) ,
78
85
]
@@ -83,6 +90,7 @@ const PATH_CONFIG = config.get('dir_path') as Config['dir_path'];
83
90
exclude : [ '/api/**' ] ,
84
91
serveStaticOptions : {
85
92
fallthrough : false ,
93
+ setHeaders : setXFrameOptionsHeader ,
86
94
} ,
87
95
} ) ,
88
96
ServeStaticModule . forRoot ( {
@@ -91,6 +99,7 @@ const PATH_CONFIG = config.get('dir_path') as Config['dir_path'];
91
99
exclude : [ '/api/**' ] ,
92
100
serveStaticOptions : {
93
101
fallthrough : false ,
102
+ setHeaders : setXFrameOptionsHeader ,
94
103
} ,
95
104
} ) ,
96
105
StaticsManagementModule ,
@@ -115,7 +124,7 @@ export class AppModule implements OnModuleInit, NestModule {
115
124
116
125
configure ( consumer : MiddlewareConsumer ) {
117
126
consumer
118
- . apply ( SubpathProxyMiddleware )
127
+ . apply ( SubpathProxyMiddleware , XFrameOptionsMiddleware )
119
128
. forRoutes ( '*' ) ;
120
129
121
130
consumer
0 commit comments