Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Validate the Content-Type on PUT requests #138

Merged
merged 2 commits into from
Apr 15, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions lib/remote_storage/rest_provider.rb
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,9 @@ def get_directory_listing(user, directory)
end

def put_data(user, directory, key, data, content_type)
# Do not try to perform the PUT request when the Content-Type does not
# look like a MIME type
server.halt 415 unless content_type.match(/^.+\/.+/i)
server.halt 400 if server.env["HTTP_CONTENT_RANGE"]
server.halt 409, "Conflict" if has_name_collision?(user, directory, key)

Expand Down
10 changes: 10 additions & 0 deletions spec/shared_examples.rb
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,16 @@ def storage_class
_(last_response.body).must_equal "Precondition Failed"
end
end

describe "Content-Type" do
it "must be in the type/subtype format" do
header "Content-Type", "text"

put "/phil/food/invalid_content_type", "invalid"

_(last_response.status).must_equal 415
end
end
end

end
Expand Down