Skip to content

Commit

Permalink
feature: set crossOriginResourcePolicy to sameOrigin in most cases (#116
Browse files Browse the repository at this point in the history
)
  • Loading branch information
levivilet authored Dec 23, 2024
1 parent d5b4c05 commit e522cee
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export const value = 'cross-origin'
export const SameOrigin = 'same-origin'
export const CrossOrigin = 'cross-origin'
6 changes: 4 additions & 2 deletions src/parts/DefaultHeaders/DefaultHeaders.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import * as HttpHeader from '../HttpHeader/HttpHeader.ts'

export const defaultHeaders = {
'Cross-Origin-Resource-Policy': 'cross-origin',
'Cross-Origin-Embedder-Policy': 'require-corp',
[HttpHeader.CrossOriginResourcePolicy]: 'cross-origin',
[HttpHeader.CrossOriginEmbedderPolicy]: 'require-corp',
}
2 changes: 1 addition & 1 deletion src/parts/GetHeaders/GetHeaders.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export const getHeaders = (absolutePath: string, etag?: string): any => {
// TODO support strong csp with webworkers
// TODO support csp for iframes inside iframes?
if (absolutePath.endsWith('.html')) {
headers[HttpHeader.CrossOriginResourcePolicy] = CrossOriginResourcePolicy.value
headers[HttpHeader.CrossOriginResourcePolicy] = CrossOriginResourcePolicy.SameOrigin
headers[HttpHeader.CrossOriginEmbedderPolicy] = CrossOriginEmbedderPolicy.value
} else {
headers[HttpHeader.CrossOriginResourcePolicy] = 'same-origin'
Expand Down
2 changes: 1 addition & 1 deletion src/parts/GetIndexResponse/GetIndexResponse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export const getIndexResponse = async (info: Info): Promise<any> => {
[HttpHeader.ContentSecurityPolicy]: info.contentSecurityPolicy,
[HttpHeader.CrossOriginEmbedderPolicy]: CrossOriginEmbedderPolicy.value,
[HttpHeader.CrossOriginOpenerPolicy]: CrossOriginOpenerPolicy.value,
[HttpHeader.CrossOriginResourcePolicy]: CrossOriginResourcePolicy.value,
[HttpHeader.CrossOriginResourcePolicy]: CrossOriginResourcePolicy.SameOrigin, // TODO find out why in browser it works differently than in electron
},
},
}
Expand Down
2 changes: 1 addition & 1 deletion src/parts/HandleIndexHtml/HandleIndexHtml.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export const handleIndexHtml = async (
const csp = GetContentSecurityPolicyDocument.getContentSecurityPolicyDocument(contentSecurityPolicy)
const contentType = GetContentType.getContentType(filePath)
const headers = {
[HttpHeader.CrossOriginResourcePolicy]: CrossOriginResourcePolicy.value,
[HttpHeader.CrossOriginResourcePolicy]: CrossOriginResourcePolicy.CrossOrigin,
[HttpHeader.CrossOriginEmbedderPolicy]: CrossOriginEmbedderPolicy.value,
[HttpHeader.ContentSecurityPolicy]: csp,
[HttpHeader.ContentType]: contentType,
Expand Down
2 changes: 1 addition & 1 deletion test/GetIndexResponse.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ test('getIndexResponse', async () => {
headers: {
'Content-Security-Policy': "default-src 'self'",
'Content-Type': 'text/html',
'Cross-Origin-Resource-Policy': 'cross-origin',
'Cross-Origin-Resource-Policy': 'same-origin',
'Cross-Origin-Embedder-Policy': 'require-corp',
'Cross-Origin-Opener-Policy': 'same-origin',
},
Expand Down

0 comments on commit e522cee

Please sign in to comment.