Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
47013a71
R
rails
项目概览
张重言
/
rails
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
rails
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
47013a71
编写于
4月 17, 2018
作者:
Y
Yaroslav Markin
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add the `nonce: true` option for `javascript_include_tag` helper.
上级
15d7fb90
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
28 addition
and
0 deletion
+28
-0
actionview/CHANGELOG.md
actionview/CHANGELOG.md
+6
-0
actionview/lib/action_view/helpers/asset_tag_helper.rb
actionview/lib/action_view/helpers/asset_tag_helper.rb
+8
-0
actionview/test/template/asset_tag_helper_test.rb
actionview/test/template/asset_tag_helper_test.rb
+8
-0
guides/source/security.md
guides/source/security.md
+6
-0
未找到文件。
actionview/CHANGELOG.md
浏览文件 @
47013a71
*
Add the
`nonce: true`
option for
`javascript_include_tag`
helper to
support automatic nonce generation for Content Security Policy.
Works the same way as
`javascript_tag nonce: true`
does.
*Yaroslav Markin*
*
Remove
`ActionView::Helpers::RecordTagHelper`
.
*
Remove
`ActionView::Helpers::RecordTagHelper`
.
*Yoshiyuki Hirano*
*Yoshiyuki Hirano*
...
...
actionview/lib/action_view/helpers/asset_tag_helper.rb
浏览文件 @
47013a71
...
@@ -55,6 +55,8 @@ module AssetTagHelper
...
@@ -55,6 +55,8 @@ module AssetTagHelper
# that path.
# that path.
# * <tt>:skip_pipeline</tt> - This option is used to bypass the asset pipeline
# * <tt>:skip_pipeline</tt> - This option is used to bypass the asset pipeline
# when it is set to true.
# when it is set to true.
# * <tt>:nonce<tt> - When set to true, adds an automatic nonce value if
# you have Content Security Policy enabled.
#
#
# ==== Examples
# ==== Examples
#
#
...
@@ -79,6 +81,9 @@ module AssetTagHelper
...
@@ -79,6 +81,9 @@ module AssetTagHelper
#
#
# javascript_include_tag "http://www.example.com/xmlhr.js"
# javascript_include_tag "http://www.example.com/xmlhr.js"
# # => <script src="http://www.example.com/xmlhr.js"></script>
# # => <script src="http://www.example.com/xmlhr.js"></script>
#
# javascript_include_tag "http://www.example.com/xmlhr.js", nonce: true
# # => <script src="http://www.example.com/xmlhr.js" nonce="..."></script>
def
javascript_include_tag
(
*
sources
)
def
javascript_include_tag
(
*
sources
)
options
=
sources
.
extract_options!
.
stringify_keys
options
=
sources
.
extract_options!
.
stringify_keys
path_options
=
options
.
extract!
(
"protocol"
,
"extname"
,
"host"
,
"skip_pipeline"
).
symbolize_keys
path_options
=
options
.
extract!
(
"protocol"
,
"extname"
,
"host"
,
"skip_pipeline"
).
symbolize_keys
...
@@ -90,6 +95,9 @@ def javascript_include_tag(*sources)
...
@@ -90,6 +95,9 @@ def javascript_include_tag(*sources)
tag_options
=
{
tag_options
=
{
"src"
=>
href
"src"
=>
href
}.
merge!
(
options
)
}.
merge!
(
options
)
if
tag_options
[
"nonce"
]
==
true
tag_options
[
"nonce"
]
=
content_security_policy_nonce
end
content_tag
(
"script"
.
freeze
,
""
,
tag_options
)
content_tag
(
"script"
.
freeze
,
""
,
tag_options
)
}.
join
(
"
\n
"
).
html_safe
}.
join
(
"
\n
"
).
html_safe
...
...
actionview/test/template/asset_tag_helper_test.rb
浏览文件 @
47013a71
...
@@ -29,6 +29,10 @@ def url_for(*args)
...
@@ -29,6 +29,10 @@ def url_for(*args)
"http://www.example.com"
"http://www.example.com"
end
end
def
content_security_policy_nonce
"iyhD0Yc0W+c="
end
AssetPathToTag
=
{
AssetPathToTag
=
{
%(asset_path(""))
=>
%()
,
%(asset_path(""))
=>
%()
,
%(asset_path(" "))
=>
%()
,
%(asset_path(" "))
=>
%()
,
...
@@ -421,6 +425,10 @@ def test_javascript_include_tag_default_protocol
...
@@ -421,6 +425,10 @@ def test_javascript_include_tag_default_protocol
assert_dom_equal
%(<script src="//assets.example.com/javascripts/prototype.js"></script>)
,
javascript_include_tag
(
"prototype"
)
assert_dom_equal
%(<script src="//assets.example.com/javascripts/prototype.js"></script>)
,
javascript_include_tag
(
"prototype"
)
end
end
def
test_javascript_include_tag_nonce
assert_dom_equal
%(<script src="/javascripts/bank.js" nonce="iyhD0Yc0W+c="></script>)
,
javascript_include_tag
(
"bank"
,
nonce:
true
)
end
def
test_stylesheet_path
def
test_stylesheet_path
StylePathToTag
.
each
{
|
method
,
tag
|
assert_dom_equal
(
tag
,
eval
(
method
))
}
StylePathToTag
.
each
{
|
method
,
tag
|
assert_dom_equal
(
tag
,
eval
(
method
))
}
end
end
...
...
guides/source/security.md
浏览文件 @
47013a71
...
@@ -1182,6 +1182,12 @@ as part of `html_options`. Example:
...
@@ -1182,6 +1182,12 @@ as part of `html_options`. Example:
<% end -%>
<% end -%>
```
```
The same works with
`javascript_include_tag`
:
```
html+erb
<%= javascript_include_tag "script", nonce: true %>
```
Use
[
`csp_meta_tag`
](
http://api.rubyonrails.org/classes/ActionView/Helpers/CspHelper.html#method-i-csp_meta_tag
)
Use
[
`csp_meta_tag`
](
http://api.rubyonrails.org/classes/ActionView/Helpers/CspHelper.html#method-i-csp_meta_tag
)
helper to create a meta tag "csp-nonce" with the per-session nonce value
helper to create a meta tag "csp-nonce" with the per-session nonce value
for allowing inline
`<script>`
tags.
for allowing inline
`<script>`
tags.
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录