Skip to content
GitLab
菜单
为什么选择 GitLab
定价
联系销售
探索
为什么选择 GitLab
定价
联系销售
探索
登录
获取免费试用
主导航
搜索或转到…
项目
GitLab
管理
动态
成员
标记
计划
议题
议题看板
里程碑
迭代
需求
代码
合并请求
仓库
分支
提交
标签
仓库图
比较修订版本
代码片段
锁定的文件
构建
流水线
作业
流水线计划
测试用例
产物
部署
发布
Package registry
Container registry
模型注册表
运维
环境
Terraform 模块
监控
事件
服务台
分析
价值流分析
贡献者分析
CI/CD 分析
仓库分析
代码评审分析
议题分析
洞察
模型实验
效能分析
帮助
帮助
支持
GitLab 文档
比较 GitLab 各版本
社区论坛
为极狐GitLab 提交贡献
提交反馈
隐私声明
快捷键
?
新增功能
4
代码片段
群组
项目
显示更多面包屑
gitlab-cn
GitLab
提交
383e747d
提交
383e747d
编辑于
3 years ago
作者:
Rohit Shambhuni
提交者:
Douglas Barbosa Alexandre
3 years ago
浏览文件
操作
下载
补丁
差异文件
Adding websocket origins to connect-src to support Safari
上级
3b9aa8e4
No related branches found
No related tags found
无相关合并请求
变更
2
隐藏空白变更内容
行内
左右并排
显示
2 个更改的文件
lib/gitlab/content_security_policy/config_loader.rb
+20
-0
20 个添加, 0 个删除
lib/gitlab/content_security_policy/config_loader.rb
spec/lib/gitlab/content_security_policy/config_loader_spec.rb
+26
-1
26 个添加, 1 个删除
.../lib/gitlab/content_security_policy/config_loader_spec.rb
有
46 个添加
和
1 个删除
lib/gitlab/content_security_policy/config_loader.rb
+
20
−
0
浏览文件 @
383e747d
...
@@ -35,6 +35,10 @@ def self.default_directives
...
@@ -35,6 +35,10 @@ def self.default_directives
# However Safari seems to read child-src first so we'll just keep both equal
# However Safari seems to read child-src first so we'll just keep both equal
directives
[
'child_src'
]
=
directives
[
'frame_src'
]
directives
[
'child_src'
]
=
directives
[
'frame_src'
]
# connect_src with 'self' includes https/wss variations of the origin,
# however, safari hasn't covered this yet and we need to explicitly add
# support for websocket origins until Safari catches up with the specs
allow_websocket_connections
(
directives
)
allow_webpack_dev_server
(
directives
)
if
Rails
.
env
.
development?
allow_webpack_dev_server
(
directives
)
if
Rails
.
env
.
development?
allow_cdn
(
directives
,
Settings
.
gitlab
.
cdn_host
)
if
Settings
.
gitlab
.
cdn_host
.
present?
allow_cdn
(
directives
,
Settings
.
gitlab
.
cdn_host
)
if
Settings
.
gitlab
.
cdn_host
.
present?
allow_customersdot
(
directives
)
if
Rails
.
env
.
development?
&&
ENV
[
'CUSTOMER_PORTAL_URL'
].
present?
allow_customersdot
(
directives
)
if
Rails
.
env
.
development?
&&
ENV
[
'CUSTOMER_PORTAL_URL'
].
present?
...
@@ -67,6 +71,22 @@ def arguments_for(directive)
...
@@ -67,6 +71,22 @@ def arguments_for(directive)
arguments
.
strip
.
split
(
' '
).
map
(
&
:strip
)
arguments
.
strip
.
split
(
' '
).
map
(
&
:strip
)
end
end
def
self
.
allow_websocket_connections
(
directives
)
http_ports
=
[
80
,
443
]
host
=
Gitlab
.
config
.
gitlab
.
host
port
=
Gitlab
.
config
.
gitlab
.
port
secure
=
Gitlab
.
config
.
gitlab
.
https
protocol
=
secure
?
'wss'
:
'ws'
ws_url
=
"
#{
protocol
}
://
#{
host
}
"
unless
http_ports
.
include?
(
port
)
ws_url
=
"
#{
ws_url
}
:
#{
port
}
"
end
append_to_directive
(
directives
,
'connect_src'
,
ws_url
)
end
def
self
.
allow_webpack_dev_server
(
directives
)
def
self
.
allow_webpack_dev_server
(
directives
)
secure
=
Settings
.
webpack
.
dev_server
[
'https'
]
secure
=
Settings
.
webpack
.
dev_server
[
'https'
]
host_and_port
=
"
#{
Settings
.
webpack
.
dev_server
[
'host'
]
}
:
#{
Settings
.
webpack
.
dev_server
[
'port'
]
}
"
host_and_port
=
"
#{
Settings
.
webpack
.
dev_server
[
'host'
]
}
:
#{
Settings
.
webpack
.
dev_server
[
'port'
]
}
"
...
...
此差异已折叠。
点击以展开。
spec/lib/gitlab/content_security_policy/config_loader_spec.rb
+
26
−
1
浏览文件 @
383e747d
...
@@ -11,6 +11,7 @@
...
@@ -11,6 +11,7 @@
directives:
{
directives:
{
base_uri:
'http://example.com'
,
base_uri:
'http://example.com'
,
child_src:
"'self' https://child.example.com"
,
child_src:
"'self' https://child.example.com"
,
connect_src:
"'self' ws://example.com"
,
default_src:
"'self' https://other.example.com"
,
default_src:
"'self' https://other.example.com"
,
script_src:
"'self' https://script.exammple.com "
,
script_src:
"'self' https://script.exammple.com "
,
worker_src:
"data: https://worker.example.com"
,
worker_src:
"data: https://worker.example.com"
,
...
@@ -52,6 +53,28 @@
...
@@ -52,6 +53,28 @@
expect
(
directives
[
'child_src'
]).
to
eq
(
directives
[
'frame_src'
])
expect
(
directives
[
'child_src'
]).
to
eq
(
directives
[
'frame_src'
])
end
end
context
'adds all websocket origins to support Safari'
do
it
'with insecure domain'
do
stub_config_setting
(
host:
'example.com'
,
https:
false
)
expect
(
directives
[
'connect_src'
]).
to
eq
(
"'self' ws://example.com"
)
end
it
'with secure domain'
do
stub_config_setting
(
host:
'example.com'
,
https:
true
)
expect
(
directives
[
'connect_src'
]).
to
eq
(
"'self' wss://example.com"
)
end
it
'with custom port'
do
stub_config_setting
(
host:
'example.com'
,
port:
'1234'
)
expect
(
directives
[
'connect_src'
]).
to
eq
(
"'self' ws://example.com:1234"
)
end
it
'with custom port and secure domain'
do
stub_config_setting
(
host:
'example.com'
,
https:
true
,
port:
'1234'
)
expect
(
directives
[
'connect_src'
]).
to
eq
(
"'self' wss://example.com:1234"
)
end
end
context
'when CDN host is defined'
do
context
'when CDN host is defined'
do
before
do
before
do
stub_config_setting
(
cdn_host:
'https://example.com'
)
stub_config_setting
(
cdn_host:
'https://example.com'
)
...
@@ -67,10 +90,11 @@
...
@@ -67,10 +90,11 @@
context
'when sentry is configured'
do
context
'when sentry is configured'
do
before
do
before
do
stub_sentry_settings
stub_sentry_settings
stub_config_setting
(
host:
'example.com'
)
end
end
it
'adds sentry path to CSP without user'
do
it
'adds sentry path to CSP without user'
do
expect
(
directives
[
'connect_src'
]).
to
eq
(
"'self' dummy://example.com/43"
)
expect
(
directives
[
'connect_src'
]).
to
eq
(
"'self'
ws://example.com
dummy://example.com/43"
)
end
end
end
end
...
@@ -113,6 +137,7 @@ def expected_config(directive)
...
@@ -113,6 +137,7 @@ def expected_config(directive)
expect
(
policy
.
directives
[
'base-uri'
]).
to
eq
([
csp_config
[
:directives
][
:base_uri
]])
expect
(
policy
.
directives
[
'base-uri'
]).
to
eq
([
csp_config
[
:directives
][
:base_uri
]])
expect
(
policy
.
directives
[
'default-src'
]).
to
eq
(
expected_config
(
:default_src
))
expect
(
policy
.
directives
[
'default-src'
]).
to
eq
(
expected_config
(
:default_src
))
expect
(
policy
.
directives
[
'connect-src'
]).
to
eq
(
expected_config
(
:connect_src
))
expect
(
policy
.
directives
[
'child-src'
]).
to
eq
(
expected_config
(
:child_src
))
expect
(
policy
.
directives
[
'child-src'
]).
to
eq
(
expected_config
(
:child_src
))
expect
(
policy
.
directives
[
'worker-src'
]).
to
eq
(
expected_config
(
:worker_src
))
expect
(
policy
.
directives
[
'worker-src'
]).
to
eq
(
expected_config
(
:worker_src
))
expect
(
policy
.
directives
[
'report-uri'
]).
to
eq
(
expected_config
(
:report_uri
))
expect
(
policy
.
directives
[
'report-uri'
]).
to
eq
(
expected_config
(
:report_uri
))
...
...
此差异已折叠。
点击以展开。
预览
0%
加载中
请重试
或
添加新附件
.
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
保存评论
取消
想要评论请
注册
或
登录