Skip to content
This repository was archived by the owner on Jun 2, 2021. It is now read-only.

Commit 9997811

Browse files
reidmitBrian Cunnie
andcommitted
🐞 v3: Don't 500 UAA Client GUIDS with exotic chars
- Creating a user who happens a UAA client allows setting the GUID - The GUID can be set to an arbitrary set of characters, e.g. `+(select*from(select(sleep(20)))a)+` - [note: the previous SQL injection attempt did not work, and does not work] - The character is properly created, but can no longer be retrieved via `GET /v3/users/:guid`; CAPI returns a 500 - We now `CGI.escape()` the GUID to prevent `URI::HTTP.build` from throwing an error when we format its link URL (in `ApiUrlBuilder`) [finishes #172744797] Co-authored-by: Brian Cunnie <bcunnie@pivotal.io> Co-authored-by: Reid Mitchell <rmitchell@pivotal.io>
1 parent cad908a commit 9997811

2 files changed

Lines changed: 16 additions & 1 deletion

File tree

app/presenters/v3/user_presenter.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ def user
4141
def build_links
4242
{
4343
self: {
44-
href: url_builder.build_url(path: "/v3/users/#{user.guid}")
44+
href: url_builder.build_url(path: "/v3/users/#{CGI.escape(user.guid)}")
4545
}
4646
}
4747
end

spec/request/users_spec.rb

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -455,6 +455,21 @@
455455
end
456456
end
457457
end
458+
459+
context 'when the user has a guid with strange characters' do
460+
let(:weird_user) { VCAP::CloudController::User.make(guid: 'weird-/(%)') }
461+
462+
before do
463+
allow(uaa_client).to receive(:users_for_ids).with([weird_user.guid]).and_return({})
464+
end
465+
466+
it 'returns the user successfully' do
467+
get "/v3/users/#{CGI.escape(weird_user.guid)}", nil, admin_headers
468+
expect(last_response).to have_status_code(200)
469+
expect(parsed_response['guid']).to eq('weird-/(%)')
470+
expect(parsed_response['links']['self']['href']).to eq(link_prefix + '/v3/users/' + CGI.escape(weird_user.guid))
471+
end
472+
end
458473
end
459474

460475
describe 'POST /v3/users' do

0 commit comments

Comments
 (0)