Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
32ffd342
Commit
32ffd342
authored
Jun 30, 2021
by
Vitaly Slobodin
Committed by
Igor Drozdov
Jun 30, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add CustomersDot to frame-src in CSP settings if set
Add CUSTOMER_PORTAL_URL to iframe-src in development only
parent
8ee19b92
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
37 additions
and
0 deletions
+37
-0
lib/gitlab/content_security_policy/config_loader.rb
lib/gitlab/content_security_policy/config_loader.rb
+7
-0
spec/lib/gitlab/content_security_policy/config_loader_spec.rb
.../lib/gitlab/content_security_policy/config_loader_spec.rb
+30
-0
No files found.
lib/gitlab/content_security_policy/config_loader.rb
View file @
32ffd342
...
@@ -37,6 +37,7 @@ module Gitlab
...
@@ -37,6 +37,7 @@ module Gitlab
allow_webpack_dev_server
(
settings_hash
)
if
Rails
.
env
.
development?
allow_webpack_dev_server
(
settings_hash
)
if
Rails
.
env
.
development?
allow_cdn
(
settings_hash
)
if
ENV
[
'GITLAB_CDN_HOST'
].
present?
allow_cdn
(
settings_hash
)
if
ENV
[
'GITLAB_CDN_HOST'
].
present?
allow_customersdot
(
settings_hash
)
if
Rails
.
env
.
development?
&&
ENV
[
'CUSTOMER_PORTAL_URL'
].
present?
settings_hash
settings_hash
end
end
...
@@ -85,6 +86,12 @@ module Gitlab
...
@@ -85,6 +86,12 @@ module Gitlab
def
self
.
append_to_directive
(
settings_hash
,
directive
,
text
)
def
self
.
append_to_directive
(
settings_hash
,
directive
,
text
)
settings_hash
[
'directives'
][
directive
]
=
"
#{
settings_hash
[
'directives'
][
directive
]
}
#{
text
}
"
.
strip
settings_hash
[
'directives'
][
directive
]
=
"
#{
settings_hash
[
'directives'
][
directive
]
}
#{
text
}
"
.
strip
end
end
def
self
.
allow_customersdot
(
settings_hash
)
customersdot_host
=
ENV
[
'CUSTOMER_PORTAL_URL'
]
append_to_directive
(
settings_hash
,
'frame_src'
,
customersdot_host
)
end
end
end
end
end
end
end
spec/lib/gitlab/content_security_policy/config_loader_spec.rb
View file @
32ffd342
...
@@ -61,6 +61,36 @@ RSpec.describe Gitlab::ContentSecurityPolicy::ConfigLoader do
...
@@ -61,6 +61,36 @@ RSpec.describe Gitlab::ContentSecurityPolicy::ConfigLoader do
expect
(
directives
[
'font_src'
]).
to
eq
(
"'self' https://example.com"
)
expect
(
directives
[
'font_src'
]).
to
eq
(
"'self' https://example.com"
)
end
end
end
end
context
'when CUSTOMER_PORTAL_URL is set'
do
before
do
stub_env
(
'CUSTOMER_PORTAL_URL'
,
'https://customers.example.com'
)
end
context
'when in production'
do
before
do
allow
(
Rails
).
to
receive
(
:env
).
and_return
(
ActiveSupport
::
StringInquirer
.
new
(
'production'
))
end
it
'does not add CUSTOMER_PORTAL_URL to CSP'
do
directives
=
settings
[
'directives'
]
expect
(
directives
[
'frame_src'
]).
to
eq
(
"'self' https://www.google.com/recaptcha/ https://www.recaptcha.net/ https://content.googleapis.com https://content-compute.googleapis.com https://content-cloudbilling.googleapis.com https://content-cloudresourcemanager.googleapis.com"
)
end
end
context
'when in development'
do
before
do
allow
(
Rails
).
to
receive
(
:env
).
and_return
(
ActiveSupport
::
StringInquirer
.
new
(
'development'
))
end
it
'adds CUSTOMER_PORTAL_URL to CSP'
do
directives
=
settings
[
'directives'
]
expect
(
directives
[
'frame_src'
]).
to
eq
(
"'self' https://www.google.com/recaptcha/ https://www.recaptcha.net/ https://content.googleapis.com https://content-compute.googleapis.com https://content-cloudbilling.googleapis.com https://content-cloudresourcemanager.googleapis.com https://customers.example.com"
)
end
end
end
end
end
describe
'#load'
do
describe
'#load'
do
...
...
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