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
ecf46692
Commit
ecf46692
authored
Sep 06, 2022
by
tom
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
use header instead of meta tag
parent
98e573b8
Changes
7
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
45 additions
and
32 deletions
+45
-32
.env.example
.env.example
+2
-0
headers.js
configs/nextjs/headers.js
+6
-0
getCspPolicy.js
lib/csp/getCspPolicy.js
+25
-18
isDev.ts
lib/isDev.ts
+0
-3
networks.ts
lib/networks.ts
+3
-6
getSupportedNetworks.js
lib/networks/getSupportedNetworks.js
+9
-0
_document.tsx
pages/_document.tsx
+0
-5
No files found.
.env.example
View file @
ecf46692
...
@@ -4,6 +4,8 @@ NEXT_PUBLIC_SENTRY_DSN=xxx
...
@@ -4,6 +4,8 @@ NEXT_PUBLIC_SENTRY_DSN=xxx
SENTRY_ORG=block-scout
SENTRY_ORG=block-scout
SENTRY_PROJECT=new-ui
SENTRY_PROJECT=new-ui
SENTRY_AUTH_TOKEN=xxx
SENTRY_AUTH_TOKEN=xxx
SENTRY_IGNORE_API_RESOLUTION_ERROR=1
SENTRY_CSP_REPORT_URI=xxx
NEXT_PUBLIC_BLOCKSCOUT_VERSION=xxx
NEXT_PUBLIC_BLOCKSCOUT_VERSION=xxx
NEXT_PUBLIC_FOOTER_GITHUB_LINK=https://github.com/blockscout/blockscout
NEXT_PUBLIC_FOOTER_GITHUB_LINK=https://github.com/blockscout/blockscout
NEXT_PUBLIC_FOOTER_TWITTER_LINK=https://www.twitter.com/blockscoutcom
NEXT_PUBLIC_FOOTER_TWITTER_LINK=https://www.twitter.com/blockscoutcom
...
...
configs/nextjs/headers.js
View file @
ecf46692
const
getCspPolicy
=
require
(
'
../../lib/csp/getCspPolicy
'
);
async
function
headers
()
{
async
function
headers
()
{
return
[
return
[
{
{
...
@@ -12,6 +14,10 @@ async function headers() {
...
@@ -12,6 +14,10 @@ async function headers() {
key
:
'
X-Content-Type-Options
'
,
key
:
'
X-Content-Type-Options
'
,
value
:
'
nosniff
'
,
value
:
'
nosniff
'
,
},
},
{
key
:
'
Content-Security-Policy-Report-Only
'
,
value
:
getCspPolicy
(),
},
],
],
},
},
];
];
...
...
lib/csp/getCspPolicy.
t
s
→
lib/csp/getCspPolicy.
j
s
View file @
ecf46692
import
isDev
from
'
lib/isDev
'
;
const
getSupportedNetworks
=
require
(
'
../networks/getSupportedNetworks
'
);
import
{
NETWORKS
}
from
'
lib/networks
'
;
const
KEY_WORDS
=
{
enum
KEY_WORDS
{
BLOB
:
'
blob:
'
,
BLOB
=
'
blob:
'
,
DATA
:
'
data:
'
,
DATA
=
'
data:
'
,
NONE
:
'
\'
none
\'
'
,
NONE
=
'
\'
none
\'
'
,
REPORT_SAMPLE
:
`'report-sample'`
,
REPORT_SAMPLE
=
`'report-sample'`
,
SELF
:
'
\'
self
\'
'
,
SELF
=
'
\'
self
\'
'
,
STRICT_DYNAMIC
:
`'strict-dynamic'`
,
STRICT_DYNAMIC
=
`'strict-dynamic'`
,
UNSAFE_INLINE
:
'
\'
unsafe-inline
\'
'
,
UNSAFE_INLINE
=
'
\'
unsafe-inline
\'
'
,
UNSAFE_EVAL
:
'
\'
unsafe-eval
\'
'
,
UNSAFE_EVAL
=
'
\'
unsafe-eval
\'
'
,
};
}
const
MAIN_DOMAINS
=
[
'
*.blockscout.com
'
,
'
blockscout.com
'
];
const
MAIN_DOMAINS
=
[
'
*.blockscout.com
'
,
'
blockscout.com
'
];
const
isDev
=
process
.
env
.
NODE_ENV
===
'
development
'
;
function
getNetworksExternalAssets
()
{
function
getNetworksExternalAssets
()
{
const
icons
=
NETWORKS
const
icons
=
getSupportedNetworks
()
.
filter
(({
icon
})
=>
typeof
icon
===
'
string
'
)
.
filter
(({
icon
})
=>
typeof
icon
===
'
string
'
)
.
map
(({
icon
})
=>
new
URL
(
icon
as
string
));
.
map
(({
icon
})
=>
new
URL
(
icon
));
return
icons
;
return
icons
;
}
}
...
@@ -34,7 +35,7 @@ function makePolicyMap() {
...
@@ -34,7 +35,7 @@ function makePolicyMap() {
KEY_WORDS
.
SELF
,
KEY_WORDS
.
SELF
,
// webpack hmr in safari doesn't recognize localhost as 'self' for some reason
// webpack hmr in safari doesn't recognize localhost as 'self' for some reason
isDev
()
?
'
ws://localhost:3000/_next/webpack-hmr
'
:
''
,
isDev
?
'
ws://localhost:3000/_next/webpack-hmr
'
:
''
,
// client error monitoring
// client error monitoring
'
sentry.io
'
,
'
*.sentry.io
'
,
'
sentry.io
'
,
'
*.sentry.io
'
,
...
@@ -45,7 +46,7 @@ function makePolicyMap() {
...
@@ -45,7 +46,7 @@ function makePolicyMap() {
// next.js generates and rebuilds source maps in dev using eval()
// next.js generates and rebuilds source maps in dev using eval()
// https://github.com/vercel/next.js/issues/14221#issuecomment-657258278
// https://github.com/vercel/next.js/issues/14221#issuecomment-657258278
isDev
()
?
KEY_WORDS
.
UNSAFE_EVAL
:
''
,
isDev
?
KEY_WORDS
.
UNSAFE_EVAL
:
''
,
...
MAIN_DOMAINS
,
...
MAIN_DOMAINS
,
...
@@ -96,10 +97,14 @@ function makePolicyMap() {
...
@@ -96,10 +97,14 @@ function makePolicyMap() {
'
base-uri
'
:
[
'
base-uri
'
:
[
KEY_WORDS
.
NONE
,
KEY_WORDS
.
NONE
,
],
],
'
report-uri
'
:
[
process
.
env
.
SENTRY_CSP_REPORT_URI
,
],
};
};
}
}
export
default
function
getCspPolicy
()
{
function
getCspPolicy
()
{
const
policyMap
=
makePolicyMap
();
const
policyMap
=
makePolicyMap
();
const
policyString
=
Object
.
entries
(
policyMap
)
const
policyString
=
Object
.
entries
(
policyMap
)
...
@@ -115,3 +120,5 @@ export default function getCspPolicy() {
...
@@ -115,3 +120,5 @@ export default function getCspPolicy() {
return
policyString
;
return
policyString
;
}
}
module
.
exports
=
getCspPolicy
;
lib/isDev.ts
deleted
100644 → 0
View file @
98e573b8
export
default
function
isDev
()
{
return
process
.
env
.
NODE_ENV
===
'
development
'
;
}
lib/networks.ts
View file @
ecf46692
...
@@ -9,6 +9,7 @@ import optimismIcon from 'icons/networks/optimism.svg';
...
@@ -9,6 +9,7 @@ import optimismIcon from 'icons/networks/optimism.svg';
import
poaSokolIcon
from
'
icons/networks/poa-sokol.svg
'
;
import
poaSokolIcon
from
'
icons/networks/poa-sokol.svg
'
;
import
poaIcon
from
'
icons/networks/poa.svg
'
;
import
poaIcon
from
'
icons/networks/poa.svg
'
;
import
rskIcon
from
'
icons/networks/rsk.svg
'
;
import
rskIcon
from
'
icons/networks/rsk.svg
'
;
import
getSupportedNetworks
from
'
lib/networks/getSupportedNetworks
'
;
// will change later when we agree how to host network icons
// will change later when we agree how to host network icons
const
ICONS
:
Record
<
string
,
React
.
FunctionComponent
<
React
.
SVGAttributes
<
SVGElement
>>>
=
{
const
ICONS
:
Record
<
string
,
React
.
FunctionComponent
<
React
.
SVGAttributes
<
SVGElement
>>>
=
{
...
@@ -25,12 +26,8 @@ const ICONS: Record<string, React.FunctionComponent<React.SVGAttributes<SVGEleme
...
@@ -25,12 +26,8 @@ const ICONS: Record<string, React.FunctionComponent<React.SVGAttributes<SVGEleme
};
};
export
const
NETWORKS
:
Array
<
Network
>
=
(()
=>
{
export
const
NETWORKS
:
Array
<
Network
>
=
(()
=>
{
try
{
const
networksFromConfig
:
Array
<
Network
>
=
getSupportedNetworks
();
const
networksFromConfig
:
Array
<
Network
>
=
JSON
.
parse
(
process
.
env
.
NEXT_PUBLIC_SUPPORTED_NETWORKS
||
'
[]
'
);
return
networksFromConfig
.
map
((
network
)
=>
({
...
network
,
icon
:
network
.
icon
||
ICONS
[
`
${
network
.
type
}
/
${
network
.
subType
}
`
]
}));
return
networksFromConfig
.
map
((
network
)
=>
({
...
network
,
icon
:
network
.
icon
||
ICONS
[
`
${
network
.
type
}
/
${
network
.
subType
}
`
]
}));
}
catch
(
error
)
{
return
[];
}
})();
})();
// for easy env creation
// for easy env creation
...
...
lib/networks/getSupportedNetworks.js
0 → 100644
View file @
ecf46692
function
getSupportedNetworks
()
{
try
{
return
JSON
.
parse
(
process
.
env
.
NEXT_PUBLIC_SUPPORTED_NETWORKS
||
'
[]
'
);
}
catch
(
error
)
{
return
[];
}
}
module
.
exports
=
getSupportedNetworks
;
pages/_document.tsx
View file @
ecf46692
...
@@ -2,7 +2,6 @@ import { ColorModeScript } from '@chakra-ui/react';
...
@@ -2,7 +2,6 @@ import { ColorModeScript } from '@chakra-ui/react';
import
Document
,
{
Html
,
Head
,
Main
,
NextScript
}
from
'
next/document
'
;
import
Document
,
{
Html
,
Head
,
Main
,
NextScript
}
from
'
next/document
'
;
import
React
from
'
react
'
;
import
React
from
'
react
'
;
import
getCspPolicy
from
'
lib/csp/getCspPolicy
'
;
import
theme
from
'
theme
'
;
import
theme
from
'
theme
'
;
class
MyDocument
extends
Document
{
class
MyDocument
extends
Document
{
...
@@ -14,10 +13,6 @@ class MyDocument extends Document {
...
@@ -14,10 +13,6 @@ class MyDocument extends Document {
href=
"https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600&display=swap"
href=
"https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600&display=swap"
rel=
"stylesheet"
rel=
"stylesheet"
/>
/>
<
meta
httpEquiv=
"Content-Security-Policy"
content=
{
getCspPolicy
()
}
/>
</
Head
>
</
Head
>
<
body
>
<
body
>
<
ColorModeScript
initialColorMode=
{
theme
.
config
.
initialColorMode
}
/>
<
ColorModeScript
initialColorMode=
{
theme
.
config
.
initialColorMode
}
/>
...
...
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