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

Add HPKP support #132

Merged
merged 1 commit into from
May 7, 2015
Merged

Add HPKP support #132

merged 1 commit into from
May 7, 2015

Conversation

thirstscolr
Copy link
Contributor

I've added support for HPKP headers now that it is supported in both Chrome and Firefox.

pin_directives,
report_uri_directive,
subdomain_directive
].join.strip
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: can you join(';') instead of prefixing some with "; ..." ?

@oreoshake
Copy link
Contributor

Damn you 1.8.7. I'm ready to drop support and the timing is right given the pending 2.0 release.

return unless request.ssl?
config = self.class.options_for :hpkp, options

return if config == false || config.nil?
Copy link
Contributor

Choose a reason for hiding this comment

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

nice. can you add a test ensuring this header isn't set by default?

@oreoshake
Copy link
Contributor

I'd love an additional sanity check from someone with experience working with the header. @ptoomey3 ? Did the pin-* value need to be quoted or something?

return '' if @pins.nil?
@pins.collect do |pin|
pin.map do |token, hash|
"; pin-#{token}=\"#{hash}\"" if HASH_ALGORITHMS.include?(token)
Copy link
Contributor

Choose a reason for hiding this comment

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

please add a test for the pin values

Copy link
Member

Choose a reason for hiding this comment

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

@oreoshake - This (\"#{hash}\") is the quoting that is necessary in Firefox 35 and will soon be mandatory in Chrome Canary. 👍

@oreoshake
Copy link
Contributor

If you merge master, the build will pass on 1.8.7

def report_uri_directive
return '' if @report_uri.nil?

if @report_uri.start_with?('//')
Copy link
Member

Choose a reason for hiding this comment

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

This block seems unneeded. Supporting a scheme relative URL in the config implies the resulting final URL will go over http or https based on some sort of context. But, it will always get set to go over https. I vote that report_uri is documented simply as :report_uri => "http[s]://example.com/uri-directive".

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍

@ptoomey3
Copy link
Member

I just gave that a quick glance, but left some initial feedback. More generally, I would be hesitant to set this for Chrome, as the current stable implementation has a number of bugs:

https://code.google.com/p/chromium/issues/detail?id=444511
https://code.google.com/p/chromium/issues/detail?id=412866
.. I'd have to double check if there are any additional known issues

The above bugs prevent max-age from working, doesn't let you revoke/rotate out a known pin, and always sets the includeSubdomains directive even when the policy does NOT have it set. So, I'd be a bit cautious with putting Public-Key-Pins in a release until things settle down. Supposedly these will be fixed in the next Canary release, but I haven't had a chance to validate the fixes yet. Also, I haven't played around with Firefox 35 as much, but I haven't yet seen anything unexpected or that violates the spec in my limited testing.

@@ -8,6 +8,7 @@ The gem will automatically apply several headers that are related to security.
- X-Content-Type-Options - [Prevent content type sniffing](http://msdn.microsoft.com/en-us/library/ie/gg622941\(v=vs.85\).aspx)
- X-Download-Options - [Prevent file downloads opening](http://msdn.microsoft.com/en-us/library/ie/jj542450(v=vs.85).aspx)
- X-Permitted-Cross-Domain-Policies - [Restrict Adobe Flash Player's access to data](https://www.adobe.com/devnet/adobe-media-server/articles/cross-domain-xml-for-streaming.html)
- Public Key Pinning - Pin certificate fingerprints in the browser to prevent man-in-the-middle attacks due to compromised Certificate Authorites. [Public Key Pinnning Specification](https://tools.ietf.org/html/draft-ietf-websec-key-pinning-20)
Copy link
Member

Choose a reason for hiding this comment

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

I think draft 21 is the latest.


it "allows you to specify a report-uri with app_name" do
should_assign_header(HPKP_HEADER_NAME, "max-age=1234; report-uri=\"https://foobar.com?enforce=true&app_name=my_app\"")
subject.set_hpkp_header(max_age: 1234, report_uri: "https://foobar.com", app_name: "my_app", tag_report_uri: true, enforce: true)
Copy link
Contributor

Choose a reason for hiding this comment

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

please use the pre-1.9 hash syntax => (sorry, still need to support 1.8.7)

@oreoshake
Copy link
Contributor

@ptoomey3 what say you, is hpkp ready for inclusion? Any browser quirks worth working around?

@ptoomey3
Copy link
Member

I haven't actually tested it in Chrome V42 stable, but when I tested Chrome V42 beta the HPKP bug was fixed. So, in all likelihood, yeah, this should be stable enough in Chrome/Firefox to be useful.

@ptoomey3
Copy link
Member

Any browser quirks worth working around?

I don't believe so.

@oreoshake oreoshake mentioned this pull request May 6, 2015
@oreoshake oreoshake merged commit 8b01d24 into github:master May 7, 2015
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.

None yet

3 participants