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
54205175
Commit
54205175
authored
Mar 03, 2023
by
tom
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix prod build
parent
fb6694f6
Changes
10
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
45 additions
and
46 deletions
+45
-46
generateCspPolicy.ts
lib/csp/generateCspPolicy.ts
+9
-21
ad.ts
lib/csp/policies/ad.ts
+1
-1
app.ts
lib/csp/policies/app.ts
+1
-1
googleAnalytics.ts
lib/csp/policies/googleAnalytics.ts
+1
-1
googleFonts.ts
lib/csp/policies/googleFonts.ts
+1
-1
googleReCaptcha.ts
lib/csp/policies/googleReCaptcha.ts
+1
-1
index.ts
lib/csp/policies/index.ts
+7
-17
sentry.ts
lib/csp/policies/sentry.ts
+1
-1
walletConnect.ts
lib/csp/policies/walletConnect.ts
+1
-1
utils.ts
lib/csp/utils.ts
+22
-1
No files found.
lib/csp/generateCspPolicy.ts
View file @
54205175
import
_mergeWith
from
'
lodash/mergeWith
'
;
import
*
as
descriptors
from
'
./policies
'
;
import
*
as
descriptors
from
'
./policies
'
;
import
{
makePolicyString
}
from
'
./utils
'
;
import
{
makePolicyString
,
mergeDescriptors
}
from
'
./utils
'
;
const
concat
=
(
one
:
Array
<
unknown
>
|
undefined
,
two
:
Array
<
unknown
>
|
undefined
)
=>
one
?
one
.
concat
(
two
||
[])
:
two
;
function
generateCspPolicy
()
{
function
generateCspPolicy
()
{
const
policyDescriptor
=
_mergeWith
(
const
policyDescriptor
=
mergeDescriptors
(
_mergeWith
(
descriptors
.
app
(),
descriptors
.
app
(),
descriptors
.
ad
(),
descriptors
.
ad
(),
descriptors
.
googleAnalytics
(),
descriptors
.
googleAnalytics
(),
descriptors
.
googleFonts
(),
descriptors
.
googleFonts
(),
descriptors
.
googleReCaptcha
(),
concat
,
descriptors
.
sentry
(),
),
descriptors
.
walletConnect
(),
_mergeWith
(
descriptors
.
googleReCaptcha
(),
descriptors
.
sentry
(),
descriptors
.
walletConnect
(),
concat
,
),
concat
,
);
);
return
makePolicyString
(
policyDescriptor
);
return
makePolicyString
(
policyDescriptor
);
...
...
lib/csp/policies/ad.ts
View file @
54205175
...
@@ -2,7 +2,7 @@ import type CspDev from 'csp-dev';
...
@@ -2,7 +2,7 @@ import type CspDev from 'csp-dev';
import
isSelfHosted
from
'
lib/isSelfHosted
'
;
import
isSelfHosted
from
'
lib/isSelfHosted
'
;
export
default
function
generateAdDescriptor
():
CspDev
.
DirectiveDescriptor
{
export
function
ad
():
CspDev
.
DirectiveDescriptor
{
if
(
!
isSelfHosted
())
{
if
(
!
isSelfHosted
())
{
return
{};
return
{};
}
}
...
...
lib/csp/policies/app.ts
View file @
54205175
...
@@ -19,7 +19,7 @@ function getMarketplaceAppsHosts() {
...
@@ -19,7 +19,7 @@ function getMarketplaceAppsHosts() {
};
};
}
}
export
default
function
generateAppDescriptor
():
CspDev
.
DirectiveDescriptor
{
export
function
app
():
CspDev
.
DirectiveDescriptor
{
const
marketplaceAppsHosts
=
getMarketplaceAppsHosts
();
const
marketplaceAppsHosts
=
getMarketplaceAppsHosts
();
return
{
return
{
...
...
lib/csp/policies/googleAnalytics.ts
View file @
54205175
...
@@ -2,7 +2,7 @@ import type CspDev from 'csp-dev';
...
@@ -2,7 +2,7 @@ import type CspDev from 'csp-dev';
import
appConfig
from
'
configs/app/config
'
;
import
appConfig
from
'
configs/app/config
'
;
export
default
function
generateGoogleAnalyticsDescriptor
():
CspDev
.
DirectiveDescriptor
{
export
function
googleAnalytics
():
CspDev
.
DirectiveDescriptor
{
if
(
!
appConfig
.
googleAnalytics
.
propertyId
)
{
if
(
!
appConfig
.
googleAnalytics
.
propertyId
)
{
return
{};
return
{};
}
}
...
...
lib/csp/policies/googleFonts.ts
View file @
54205175
import
type
CspDev
from
'
csp-dev
'
;
import
type
CspDev
from
'
csp-dev
'
;
export
default
function
generateGoogleFontsDescriptor
():
CspDev
.
DirectiveDescriptor
{
export
function
googleFonts
():
CspDev
.
DirectiveDescriptor
{
// we use Inter and Poppins in the app
// we use Inter and Poppins in the app
return
{
return
{
...
...
lib/csp/policies/googleReCaptcha.ts
View file @
54205175
...
@@ -2,7 +2,7 @@ import type CspDev from 'csp-dev';
...
@@ -2,7 +2,7 @@ import type CspDev from 'csp-dev';
import
appConfig
from
'
configs/app/config
'
;
import
appConfig
from
'
configs/app/config
'
;
export
default
function
generateGoogleReCaptchaDescriptor
():
CspDev
.
DirectiveDescriptor
{
export
function
googleReCaptcha
():
CspDev
.
DirectiveDescriptor
{
if
(
!
appConfig
.
reCaptcha
.
siteKey
)
{
if
(
!
appConfig
.
reCaptcha
.
siteKey
)
{
return
{};
return
{};
}
}
...
...
lib/csp/policies/index.ts
View file @
54205175
import
ad
from
'
./ad
'
;
export
{
ad
}
from
'
./ad
'
;
import
app
from
'
./app
'
;
export
{
app
}
from
'
./app
'
;
import
googleAnalytics
from
'
./googleAnalytics
'
;
export
{
googleAnalytics
}
from
'
./googleAnalytics
'
;
import
googleFonts
from
'
./googleFonts
'
;
export
{
googleFonts
}
from
'
./googleFonts
'
;
import
googleReCaptcha
from
'
./googleReCaptcha
'
;
export
{
googleReCaptcha
}
from
'
./googleReCaptcha
'
;
import
sentry
from
'
./sentry
'
;
export
{
sentry
}
from
'
./sentry
'
;
import
walletConnect
from
'
./walletConnect
'
;
export
{
walletConnect
}
from
'
./walletConnect
'
;
export
{
ad
,
app
,
googleAnalytics
,
googleFonts
,
googleReCaptcha
,
sentry
,
walletConnect
,
};
lib/csp/policies/sentry.ts
View file @
54205175
import
type
CspDev
from
'
csp-dev
'
;
import
type
CspDev
from
'
csp-dev
'
;
export
default
function
generateSentryDescriptor
():
CspDev
.
DirectiveDescriptor
{
export
function
sentry
():
CspDev
.
DirectiveDescriptor
{
return
{
return
{
'
connect-src
'
:
[
'
connect-src
'
:
[
'
sentry.io
'
,
'
sentry.io
'
,
...
...
lib/csp/policies/walletConnect.ts
View file @
54205175
...
@@ -2,7 +2,7 @@ import type CspDev from 'csp-dev';
...
@@ -2,7 +2,7 @@ import type CspDev from 'csp-dev';
import
appConfig
from
'
configs/app/config
'
;
import
appConfig
from
'
configs/app/config
'
;
export
default
function
generateWalletConnectDescriptor
():
CspDev
.
DirectiveDescriptor
{
export
function
walletConnect
():
CspDev
.
DirectiveDescriptor
{
if
(
!
appConfig
.
walletConnect
.
projectId
||
!
appConfig
.
network
.
rpcUrl
)
{
if
(
!
appConfig
.
walletConnect
.
projectId
||
!
appConfig
.
network
.
rpcUrl
)
{
return
{};
return
{};
}
}
...
...
lib/csp/utils.ts
View file @
54205175
...
@@ -11,7 +11,7 @@ export const KEY_WORDS = {
...
@@ -11,7 +11,7 @@ export const KEY_WORDS = {
UNSAFE_EVAL
:
'
\'
unsafe-eval
\'
'
,
UNSAFE_EVAL
:
'
\'
unsafe-eval
\'
'
,
};
};
// we cannot use lodash/uniq
in middleware code since it calls new Set() and it'is causing an error in Next
js
// we cannot use lodash/uniq
and lodash/mergeWith in middleware code since it calls new Set() and it'is causing an error in Next.
js
// "Dynamic Code Evaluation (e. g. 'eval', 'new Function', 'WebAssembly.compile') not allowed in Edge Runtime"
// "Dynamic Code Evaluation (e. g. 'eval', 'new Function', 'WebAssembly.compile') not allowed in Edge Runtime"
export
function
unique
(
array
:
Array
<
string
|
undefined
>
)
{
export
function
unique
(
array
:
Array
<
string
|
undefined
>
)
{
const
set
:
Record
<
string
,
boolean
>
=
{};
const
set
:
Record
<
string
,
boolean
>
=
{};
...
@@ -22,6 +22,27 @@ export function unique(array: Array<string | undefined>) {
...
@@ -22,6 +22,27 @@ export function unique(array: Array<string | undefined>) {
return
Object
.
keys
(
set
);
return
Object
.
keys
(
set
);
}
}
export
function
mergeDescriptors
(...
descriptors
:
Array
<
CspDev
.
DirectiveDescriptor
>
)
{
return
descriptors
.
reduce
((
result
,
item
)
=>
{
for
(
const
_key
in
item
)
{
const
key
=
_key
as
CspDev
.
Directive
;
const
value
=
item
[
key
];
if
(
!
value
)
{
continue
;
}
if
(
result
[
key
])
{
result
[
key
]?.
push
(...
value
);
}
else
{
result
[
key
]
=
[
...
value
];
}
}
return
result
;
},
{}
as
CspDev
.
DirectiveDescriptor
);
}
export
function
makePolicyString
(
policyDescriptor
:
CspDev
.
DirectiveDescriptor
)
{
export
function
makePolicyString
(
policyDescriptor
:
CspDev
.
DirectiveDescriptor
)
{
return
Object
.
entries
(
policyDescriptor
)
return
Object
.
entries
(
policyDescriptor
)
.
map
(([
key
,
value
])
=>
{
.
map
(([
key
,
value
])
=>
{
...
...
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