8000
Skip to content

Supply access token through Authorization header#308

Merged
ConradIrwin merged 1 commit intodefunkt:masterfrom
keynslug:master
Feb 5, 2020
Merged

Supply access token through Authorization header#308
ConradIrwin merged 1 commit intodefunkt:masterfrom
keynslug:master

Conversation

@keynslug
Copy link
Copy Markdown
Contributor
@keynslug keynslug commented Feb 4, 2020

url << "?access_token=" << CGI.escape(access_token) if access_token.to_s != ''

request = Net::HTTP::Post.new(url)
request['Authorization'] = "token #{access_token}" if access_token.to_s != ''
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@keynslug thanks for this change!

In general it's unsafe to echo user-provided input into HTTP headers (as if the input contains \r\n then they can control more than just one header). The risk is very low in this context (as the access token is already assumed to be trusted), but as good practice I think we should do something like:

"token #{header_safe access_token}" where

def header_safe(x) 
   raise "invalid access_token" if x =~ /[\r\n]/
   x
end

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As Conrad notes, this is probably needed, but the input reader presently stops this anyway, so it's only an extra security step (a very good one).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh. I had an impression that it's already taken care of by these lines of code from Net::HTTPHeader:

https://github.com/ruby/ruby/blob/v2_7_0/lib/net/http/header.rb#L84-L86

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perfect, I was not aware of that!

@ConradIrwin ConradIrwin merged commit 9bd97ca into defunkt:master Feb 5, 2020
@mgmarino
Copy link
Copy Markdown
mgmarino commented Feb 6, 2020

Thanks for this! Will this be released soon, or should we rather install from the repo?

@ConradIrwin
Copy link
Copy Markdown
Collaborator
ConradIrwin commented Feb 7, 2020 via email

@keynslug
Copy link
Copy Markdown
Contributor Author
keynslug commented Feb 7, 2020

Published as v5.1.0

Wonderful! Would be great to have it tagged and provided as a release also.

gentoo-bot pushed a commit to gentoo/gentoo that referenced this pull request Feb 20, 2020
GitHub has changed the authentication method slightly, discontining
support for the old access_token query parameter. All consumers should
move to headers [1] instead. Support for the old method ends 2020/07/01.

[1] https://developer.github.com/changes/2019-11-05-deprecated-passwords-and-authorizations-api/#authenticating-using-query-parameters

Fixes: defunkt/gist#308
Signed-off-by: Robin H. Johnson <robbat2@gentoo.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants

0