-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: don't enforce https if http urls in env and related fixes 2 (#819)
- Loading branch information
Showing
4 changed files
with
55 additions
and
33 deletions.
There are no files selected for viewing
This file contains 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,7 @@ | ||
* | ||
!src | ||
!index.html | ||
!nuxt.config.ts | ||
!package.json | ||
!tsconfig.json | ||
!yarn.lock |
This file contains 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 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 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,28 +1,43 @@ | ||
const DEFAULT_HEADERS = { | ||
'X-Content-Type-Options': 'nosniff', | ||
'X-Frame-Options': 'sameorigin', | ||
'X-XSS-Protection': '1; mode=block', | ||
'Strict-Transport-Security': 'max-age=31536000; includeSubDomains; preload', | ||
'Cache-control': 'no-cache', | ||
'Content-Security-Policy': 'default-src \'self\' *; font-src \'self\' data:; img-src \'self\' data:; script-src \'self\' \'unsafe-inline\'; style-src \'self\' \'unsafe-inline\'; frame-src \'self\'; upgrade-insecure-requests; block-all-mixed-content', | ||
'Permissions-Policy': 'camera=(), geolocation=(), microphone=()', | ||
'Referrer-Policy': 'strict-origin-when-cross-origin', | ||
'X-Permitted-Cross-Domain-Policies': 'none', | ||
'Cross-Origin-Embedder-Policy': 'require-corp', | ||
'Cross-Origin-Opener-Policy': 'same-origin', | ||
'Cross-Origin-Resource-Policy': 'cross-origin', | ||
} | ||
|
||
export default defineNitroPlugin(nitroApp => { | ||
const { | ||
WEBSOCKET_URL, MIDDLEWARE_URL, NODE_URL, DEX_BACKEND_URL, CONTRACT_VERIFICATION_SERVICE_URL, | ||
} = useRuntimeConfig().public | ||
|
||
const allowHttp = [ | ||
MIDDLEWARE_URL, NODE_URL, DEX_BACKEND_URL, CONTRACT_VERIFICATION_SERVICE_URL, | ||
].some(url => url?.startsWith('http://')) || WEBSOCKET_URL?.startsWith('ws://') | ||
|
||
const DEFAULT_HEADERS = { | ||
'X-Content-Type-Options': 'nosniff', | ||
'X-Frame-Options': 'sameorigin', | ||
'X-XSS-Protection': '1; mode=block', | ||
'Strict-Transport-Security': 'max-age=31536000; includeSubDomains; preload', | ||
'Cache-control': 'no-cache', | ||
'Content-Security-Policy': [ | ||
'default-src \'self\' *', | ||
'font-src \'self\' data:', | ||
'img-src \'self\' data:', | ||
'script-src \'self\' \'unsafe-inline\'', | ||
'style-src \'self\' \'unsafe-inline\'', | ||
'frame-src \'self\'', | ||
...allowHttp ? [] : ['upgrade-insecure-requests'], | ||
'block-all-mixed-content', | ||
].join('; '), | ||
'Permissions-Policy': 'camera=(), geolocation=(), microphone=()', | ||
'Referrer-Policy': 'strict-origin-when-cross-origin', | ||
'X-Permitted-Cross-Domain-Policies': 'none', | ||
'Cross-Origin-Embedder-Policy': 'require-corp', | ||
'Cross-Origin-Opener-Policy': 'same-origin', | ||
'Cross-Origin-Resource-Policy': 'cross-origin', | ||
} | ||
|
||
nitroApp.hooks.hook('render:response', response => { | ||
delete response.headers['x-powered-by'] | ||
|
||
if (process.env.NODE_ENV !== 'production') { | ||
return | ||
} | ||
|
||
for (const header in DEFAULT_HEADERS) { | ||
response.headers[header] = DEFAULT_HEADERS[header] | ||
} | ||
Object.assign(response.headers, DEFAULT_HEADERS) | ||
}) | ||
}) |