Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
e8df5648
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,体验更适合开发者的 AI 搜索 >>
未验证
提交
e8df5648
编写于
5月 14, 2020
作者:
T
Travis Pew
提交者:
Aaron Patterson
5月 14, 2020
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Include Content-Length in signature for ActiveStorage direct upload
[CVE-2020-8162]
上级
4dcc5435
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
25 addition
and
1 deletion
+25
-1
activestorage/lib/active_storage/service/s3_service.rb
activestorage/lib/active_storage/service/s3_service.rb
+2
-1
activestorage/test/service/s3_service_test.rb
activestorage/test/service/s3_service_test.rb
+23
-0
未找到文件。
activestorage/lib/active_storage/service/s3_service.rb
浏览文件 @
e8df5648
...
...
@@ -79,7 +79,8 @@ def url(key, expires_in:, filename:, disposition:, content_type:)
def
url_for_direct_upload
(
key
,
expires_in
:,
content_type
:,
content_length
:,
checksum
:)
instrument
:url
,
key:
key
do
|
payload
|
generated_url
=
object_for
(
key
).
presigned_url
:put
,
expires_in:
expires_in
.
to_i
,
content_type:
content_type
,
content_length:
content_length
,
content_md5:
checksum
content_type:
content_type
,
content_length:
content_length
,
content_md5:
checksum
,
whitelist_headers:
[
'content-length'
]
payload
[
:url
]
=
generated_url
...
...
activestorage/test/service/s3_service_test.rb
浏览文件 @
e8df5648
...
...
@@ -31,6 +31,29 @@ class ActiveStorage::Service::S3ServiceTest < ActiveSupport::TestCase
end
end
test
"directly uploading file larger than the provided content-length does not work"
do
key
=
SecureRandom
.
base58
(
24
)
data
=
"Some text that is longer than the specified content length"
checksum
=
Digest
::
MD5
.
base64digest
(
data
)
url
=
@service
.
url_for_direct_upload
(
key
,
expires_in:
5
.
minutes
,
content_type:
"text/plain"
,
content_length:
data
.
size
-
1
,
checksum:
checksum
)
uri
=
URI
.
parse
url
request
=
Net
::
HTTP
::
Put
.
new
uri
.
request_uri
request
.
body
=
data
request
.
add_field
"Content-Type"
,
"text/plain"
request
.
add_field
"Content-MD5"
,
checksum
upload_result
=
Net
::
HTTP
.
start
(
uri
.
host
,
uri
.
port
,
use_ssl:
true
)
do
|
http
|
http
.
request
request
end
assert_equal
"403"
,
upload_result
.
code
assert_raises
ActiveStorage
::
FileNotFoundError
do
@service
.
download
(
key
)
end
ensure
@service
.
delete
key
end
test
"upload a zero byte file"
do
blob
=
directly_upload_file_blob
filename:
"empty_file.txt"
,
content_type:
nil
user
=
User
.
create!
name:
"DHH"
,
avatar:
blob
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录