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

enhanced path validation in Windows #1379

Merged
merged 2 commits into from
Feb 11, 2018
Merged

Conversation

orangetw
Copy link
Contributor

@orangetw orangetw commented Jan 9, 2018

Due to the Windows environment, more check backslashes in static! method and enhanced the path_traversal validation in rack-protection

@@ -1061,6 +1061,7 @@ def route_missing
def static!(options = {})
return if (public_dir = settings.public_folder).nil?
path = File.expand_path("#{public_dir}#{URI_INSTANCE.unescape(request.path_info)}" )
return unless path.start_with?(public_dir)
Copy link
Member

Choose a reason for hiding this comment

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

Can you add a comment about when this might be true/false?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh, sorry I misunderstood your question :(
This line check the user-supplied path must under public_dir, or it will return nil to prevent user from path traversal attack.

Copy link
Member

Choose a reason for hiding this comment

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

@kgrz Did you mean "Can you add a Ruby code comment near this line about ..."?

Copy link
Member

Choose a reason for hiding this comment

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

Hehe, yes yes. I meant a comment in the code. Didn’t notice my question was ambiguous until you pointed it out.

Copy link
Member

Choose a reason for hiding this comment

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

I agree a code comment about when path.start_with?(public_dir) would evaluate to false would be helpful. I'm actually not sure I understand when that would happen 😬

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 this is not necessary actually because . and .. have been reduced by rack-protection.
Even in the case of invalidating the :path_traversal setting on rack-protection, you should still add comment in the code if you think that it is meaningful to activate this restriction.
@orangetw Could you add the comment in the code?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The major enhancement I already commit to rack-protections (added back-slash check to the path_traversal.rb), this line(in base.rb) is just double check and ensure that there is no unknown(unexpected) attack vector.

I am not a ruby developer, so if you think that line is unnecessary, maybe only merge the changes on path_traversal.rb?

Copy link
Member

Choose a reason for hiding this comment

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

As a personal opinion, I prefer a simple structure.
Double check increases software complexity.
And yes, the essence of the problem is certainly fixed with your commit to rack-protection.
If you agree with my opinion, please drop this line.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

OK, I have done that!

Copy link
Member

Choose a reason for hiding this comment

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

Great, I'm going to check the behavior on Windows and merge this in a few days.
Thank you!

@zzak
Copy link
Member

zzak commented Jan 14, 2018

cc #1339

@namusyaka namusyaka added this to the v2.0.1 milestone Feb 6, 2018
@namusyaka namusyaka self-assigned this Feb 9, 2018
@namusyaka
Copy link
Member

Btw, thank you for sending the patch and your report!

Removed the double check line!
Copy link
Member

@namusyaka namusyaka left a comment

Choose a reason for hiding this comment

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

Looks good to me. Please wait for confirming this change on my windows machine.

@namusyaka
Copy link
Member

I've confirmed the issue, and it has been fixed correctly by this patch.
@orangetw Thank you so much!

@namusyaka namusyaka merged commit 6bcc6c3 into sinatra:master Feb 11, 2018
namusyaka added a commit to sinatra/rack-protection that referenced this pull request Feb 19, 2018
This commit has been backported from sinatra/sinatra#1379

Fixes CVE-2018-7212
@peterkeen
Copy link

peterkeen commented Feb 27, 2018

Hi folks, does this affect versions < 2.0?

@andrew-stripe
Copy link

@peterkeen: I was just looking into the same thing myself. I believe it effects all versions of rack-protection before 2.0.1. I think it would be possible to backport the fix here and cut a 1.5.4 release from the separate rack-protection repo:
https://github.com/sinatra/rack-protection/blob/v1.5.3/lib/rack/protection/path_traversal.rb

@andrew-stripe
Copy link

Ah, actually this was already backported:
https://github.com/sinatra/rack-protection/commits/stable-1.5

So this really is fixed on rack-protection ~>1.5.4 / >2.0.0 I think

@ghiculescu
Copy link

If bundle-audit told you to come here and you don't want to update to Sinatra 2.x right now, subscribe to rubysec/ruby-advisory-db#331

@namusyaka
Copy link
Member

namusyaka commented Feb 28, 2018

Yeah, rack-protection v1.5.x has not been maintained, I had backported security fix exceptionally into the 1.5-stable branch.

bess added a commit to curationexperts/epigaea that referenced this pull request Mar 5, 2018
nokogiri 1.8.2 fixes security issue https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2017-15412
rack-protection 2.0.1 fixes security issue sinatra/sinatra#1379
tmtmtmtm added a commit to everypolitician/legislative-explorer that referenced this pull request Mar 6, 2018
update Sinatra due to security advisory:

  Name: rack-protection
  Version: 1.5.3
  Advisory: CVE-2018-7212
  Criticality: Unknown
  URL: sinatra/sinatra#1379
  Title: Path traversal is possible via backslash characters on Windows.
  Solution: upgrade to >= 2.0.1, ~> 1.5.4
mkorcy pushed a commit to TuftsUniversity/mira_on_hyrax that referenced this pull request Mar 6, 2018
nokogiri 1.8.2 fixes security issue https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2017-15412
rack-protection 2.0.1 fixes security issue sinatra/sinatra#1379
robbkidd added a commit to chef/supermarket that referenced this pull request Mar 13, 2018
Addresses CVE-2018-7212 reported in rack-protection.[1] CVE does not
affect Supermarket because the vulnerability is only on Windows
platforms.

[1] sinatra/sinatra#1379

Signed-off-by: Robb Kidd <rkidd@chef.io>
kynetiv added a commit to RTICWDT/open-data-maker that referenced this pull request Mar 26, 2018
* update padrino dependencies (see rack-protection vuln)[sinatra/sinatra#1379]

* update actionview dependencies (action-html-sanitizer and loofah)
hugopl pushed a commit to hugopl/reviewit that referenced this pull request May 4, 2018
Name: rack-protection
Version: 2.0.0
Advisory: CVE-2018-7212
Criticality: Unknown
URL: sinatra/sinatra#1379
Title: Path traversal is possible via backslash characters on Windows.
Cruikshanks added a commit to DEFRA/quke-demo-app that referenced this pull request Sep 9, 2019
Because in the previous version of the gemspec we had an open reference to Sinatra it meant we were essentially saying any version would do.

Hakiri was flagging this with [CVE-2018-7212](sinatra/sinatra#1379), the resolution of which was to specify a version equal to or greater than 2.0.1
Cruikshanks added a commit to DEFRA/quke-demo-app that referenced this pull request Sep 9, 2019
Because in the previous version of the gemspec we had an open reference to Sinatra it meant we were essentially saying any version would do.

Hakiri was flagging this with [CVE-2018-7212](sinatra/sinatra#1379), the resolution of which was to specify a version equal to or greater than 2.0.1

It was then flagging this project with [CVE-2018-11627](sinatra/sinatra#1428), and again the resolution was to specify a version, this time equal to or greater than 2.0.2
Cruikshanks added a commit to DEFRA/quke-demo-app that referenced this pull request Sep 9, 2019
Because in the previous version of the gemspec we had an open reference to Sinatra it meant we were essentially saying any version would do.

Hakiri was flagging this with [CVE-2018-7212](sinatra/sinatra#1379), the resolution of which was to specify a version equal to or greater than 2.0.1

It was then flagging this project with [CVE-2018-11627](sinatra/sinatra#1428), and again the resolution was to specify a version, this time equal to or greater than 2.0.2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants