Skip to content

Commit

Permalink
Return 400 on preflight for invalid requests
Browse files Browse the repository at this point in the history
Addresses part of [#192]
  • Loading branch information
cyu committed Nov 20, 2019
1 parent ed91aef commit c8f9a61
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ All notable changes to this project will be documented in this file.
- Use Rack::Utils.escape_path instead of Rack::Utils.escape
- Require Rack 2.0 for escape_path method
- Don't try to clean path if invalid.
- Return 400 (Bad Request) on preflights with invalid path

## 1.0.6 - 2019-11-14
### Changed
Expand Down
4 changes: 3 additions & 1 deletion lib/rack/cors.rb
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,9 @@ def call(env)
" Access-Control-Request-Headers: #{env[HTTP_ACCESS_CONTROL_REQUEST_HEADERS]}"
].join("\n")
end
if env[REQUEST_METHOD] == OPTIONS and env[HTTP_ACCESS_CONTROL_REQUEST_METHOD]

if env[REQUEST_METHOD] == OPTIONS && env[HTTP_ACCESS_CONTROL_REQUEST_METHOD]
return [400, {}, []] unless Rack::Utils.valid_path?(path)
headers = process_preflight(env, path)
debug(env) do
"Preflight Headers:\n" +
Expand Down

0 comments on commit c8f9a61

Please sign in to comment.