Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
F
frontend
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
vicotor
frontend
Commits
a82753c7
Commit
a82753c7
authored
Sep 02, 2022
by
tom
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
base policies
parent
16a6063a
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
96 additions
and
0 deletions
+96
-0
getCspPolicy.js
configs/nextjs/getCspPolicy.js
+76
-0
headers.js
configs/nextjs/headers.js
+17
-0
next.config.js
next.config.js
+3
-0
No files found.
configs/nextjs/getCspPolicy.js
0 → 100644
View file @
a82753c7
const
CONSTS
=
{
BLOB
:
'
blob:
'
,
DATA
:
'
data:
'
,
NONE
:
'
\'
none
\'
'
,
REPORT_SAMPLE
:
`'report-sample'`
,
SELF
:
'
\'
self
\'
'
,
STRICT_DYNAMIC
:
`'strict-dynamic'`
,
UNSAFE_INLINE
:
'
\'
unsafe-inline
\'
'
,
UNSAFE_EVAL
:
'
\'
unsafe-eval
\'
'
,
};
const
MAIN_DOMAINS
=
[
'
*.blockscout.com
'
,
'
blockscout.com
'
];
function
makePolicyMap
()
{
return
{
'
default-src
'
:
[
CONSTS
.
NONE
,
],
'
connect-src
'
:
[
CONSTS
.
SELF
,
'
sentry.io
'
,
'
*.sentry.io
'
,
// client error monitoring
],
'
script-src
'
:
[
CONSTS
.
SELF
,
...
MAIN_DOMAINS
,
CONSTS
.
UNSAFE_INLINE
,
CONSTS
.
UNSAFE_EVAL
,
],
'
style-src
'
:
[
CONSTS
.
SELF
,
...
MAIN_DOMAINS
,
'
fonts.googleapis.com
'
,
CONSTS
.
UNSAFE_INLINE
,
],
'
img-src
'
:
[
CONSTS
.
SELF
,
CONSTS
.
DATA
,
...
MAIN_DOMAINS
,
// github avatars
'
avatars.githubusercontent.com
'
,
],
'
font-src
'
:
[
CONSTS
.
SELF
,
CONSTS
.
DATA
,
// google fonts
'
*.gstatic.com
'
,
'
fonts.googleapis.com
'
,
],
};
}
function
getCspPolicy
()
{
const
policyMap
=
makePolicyMap
();
const
policyHeader
=
Object
.
entries
(
policyMap
)
.
map
(([
key
,
value
])
=>
{
if
(
!
value
||
value
.
length
===
0
)
{
return
;
}
return
[
key
,
value
.
join
(
'
'
)
].
join
(
'
'
);
})
.
filter
(
Boolean
)
.
join
(
'
;
'
);
return
policyHeader
;
}
module
.
exports
=
getCspPolicy
;
configs/nextjs/headers.js
0 → 100644
View file @
a82753c7
const
getCspPolicy
=
require
(
'
./getCspPolicy
'
);
async
function
headers
()
{
return
[
{
source
:
'
/:path*
'
,
headers
:
[
{
key
:
'
Content-Security-Policy
'
,
value
:
getCspPolicy
(),
},
],
},
];
}
module
.
exports
=
headers
;
next.config.js
View file @
a82753c7
...
...
@@ -2,6 +2,8 @@ const { withSentryConfig } = require('@sentry/nextjs');
const
withReactSvg
=
require
(
'
next-react-svg
'
);
const
path
=
require
(
'
path
'
);
const
headers
=
require
(
'
./configs/nextjs/headers
'
);
const
moduleExports
=
{
include
:
path
.
resolve
(
__dirname
,
'
icons
'
),
reactStrictMode
:
true
,
...
...
@@ -17,6 +19,7 @@ const moduleExports = {
},
];
},
headers
,
output
:
'
standalone
'
,
};
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment