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

Safely Pass Percent Symbols in Paths #170

Merged
merged 2 commits into from
Jul 20, 2023
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
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

See this http://keepachangelog.com link for information on how we want this documented formatted.

## v5.2.0

### Fixed

- Safely Pass Percent Symbols in Paths Fixes #170

## v5.1.0

### Added
Expand Down
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
lamby (5.1.0)
lamby (5.2.0)
lambda-console-ruby
rack

Expand Down
1 change: 1 addition & 0 deletions lib/lamby/rack_http.rb
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ def cookies
def path_info
stage = event.dig('requestContext', 'stage')
spath = event.dig('requestContext', 'http', 'path') || event.dig('requestContext', 'path')
spath = event['rawPath'] if spath != event['rawPath'] && !payload_version_one?
spath.sub /\A\/#{stage}/, ''
end

Expand Down
2 changes: 1 addition & 1 deletion lib/lamby/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module Lamby
VERSION = '5.1.0'
VERSION = '5.2.0'
end
4 changes: 4 additions & 0 deletions test/dummy_app/app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ def exception
raise 'hell'
end

def percent
render
end

def cooks
cookies['1'] = '1'
cookies['2'] = '2'
Expand Down
2 changes: 2 additions & 0 deletions test/dummy_app/app/views/application/percent.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Params: <%= params[:path] %>
Request Path: <%= request.path %>
1 change: 1 addition & 0 deletions test/dummy_app/config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
post 'login', to: 'application#login'
delete 'logout', to: 'application#logout'
get 'exception', to: 'application#exception'
get 'percent/*path', to: 'application#percent'
get 'cooks', to: 'application#cooks'
get 'redirect_test', to: redirect('/')
end
11 changes: 11 additions & 0 deletions test/handler_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,17 @@ class HandlerTest < LambySpec
expect(result[:body]).must_match %r{We're sorry, but something went wrong.}
expect(result[:body]).must_match %r{This file lives in public/500.html}
end

it 'get - percent' do
event = TestHelpers::Events::HttpV2.create(
'rawPath' => '/production/percent/dwef782jkif%3d',
'requestContext' => { 'http' => {'path' => '/production/percent/dwef782jkif='} }
)
result = Lamby.handler app, event, context, rack: :http
expect(result[:statusCode]).must_equal 200
expect(result[:body]).must_match %r{Params: dwef782jkif=}
expect(result[:body]).must_match %r{Request Path: /percent/dwef782jkif%3}
end

end

Expand Down