Skip to content

Commit

Permalink
Merge pull request rails-lambda#170 from rails-lambda/PercentInPath
Browse files Browse the repository at this point in the history
Safely Pass Percent Symbols in Paths
  • Loading branch information
metaskills authored Jul 20, 2023
2 parents f812aad + b94e8a3 commit 99dc164
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 2 deletions.
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

0 comments on commit 99dc164

Please sign in to comment.