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

Catch raw hrefs as bad, warn unless wrapped in a "safe" method #45

Merged
merged 3 commits into from
Feb 23, 2012
Merged

Catch raw hrefs as bad, warn unless wrapped in a "safe" method #45

merged 3 commits into from
Feb 23, 2012

Conversation

oreoshake
Copy link
Contributor

Add concept of a safe-ening method to mark hrefs as safe

Feature:
Warn when using unsafe hrefs. This is a very specific case that as of now produces a ton of noise. This came out of an xss vuln where the value was escaped but still vulnerable.

link_to 'asdf', h(@scary)

where

@scary = 'javascript:alert(1)'

or

@scary = 'data:  # http://palpapers.plynt.com/issues/2010Oct/bypass-xss-filters/

This branch accomplishes slightly intelligent warnings by adding a new command line option to declare methods that make a string URL safe (unless there is already a standard one out there). e.g.:

$ brakeman . --url-safe-methods ensure_valid_protocol!

link_to 'asdf', ensure_valid_protocol!(@scary, :javascript)

Add concept of a safe-ening method to mark hrefs as safe

Feature:
Warn when using unsafe hrefs.  This is a very specific case that as of now produces a ton of noise.  This came out of an xss vuln where the value was escaped but still vulnerable.

    link_to 'asdf', h(@scary)

where

    @scary = 'javascript:alert(1)'

or

    @scary = 'data:  # http://palpapers.plynt.com/issues/2010Oct/bypass-xss-filters/

This branch accomplishes slightly intelligent warnings by adding a new command line option to declare methods that make a string URL safe (unless there is already a standard one out there).  e.g.:

    $ brakeman . --url-safe-methods ensure_valid_protocol!

    link_to 'asdf', ensure_valid_protocol!(@scary, :javascript)
@oreoshake
Copy link
Contributor Author

Bah, found another class of FPs. Will fix.

:submit_tag, :text_area, :text_field,
:text_field_tag, :url_encode, :url_for,
:will_paginate] ).merge tracker.options[:safe_methods]
@ignore_methods = IGNORE_METHODS.merge tracker.options[:safe_methods]
Copy link
Owner

Choose a reason for hiding this comment

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

Merge modifies the original set, so this isn't going to work out right.

@oreoshake
Copy link
Contributor Author

I'm happy with this for now.

presidentbeef added a commit that referenced this pull request Feb 23, 2012
Catch raw hrefs as bad, warn unless wrapped in a "safe" method
@presidentbeef presidentbeef merged commit a31a1bd into presidentbeef:master Feb 23, 2012
call = result[:call] = result[:call].dup
@matched = false
url_arg = process call[3][2]
return if sexp?(url_arg) && url_arg.node_type == :string_interp && !url_arg[1].chomp.empty?
Copy link
Owner

Choose a reason for hiding this comment

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

The idea is that if you are doing string interpolation, you know what you are doing?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So "http://safe.com/#{param}" is safe but "#{bad}/stuff" is not. Safe?
On Feb 22, 2012 4:50 PM, "Justin" <
reply@reply.github.com>
wrote:

  • @models = tracker.models.keys
  • @inspect_arguments = tracker.options[:check_arguments]
  • methods = tracker.find_call :target => false, :method => :link_to
  • methods.each do |call|
  •  process_result call
    
  • end
  • end
  • def process_result result
  • #Have to make a copy of this, otherwise it will be changed to
  • #an ignored method call by the code above.
  • call = result[:call] = result[:call].dup
  • @matched = false
  • url_arg = process call[3][2]
  • return if sexp?(url_arg) && url_arg.node_type == :string_interp &&
    !url_arg[1].chomp.empty?

The idea is that if you are doing string interpolation, you know what you
are doing?


Reply to this email directly or view it on GitHub:
https://github.com/presidentbeef/brakeman/pull/45/files#r478556

Copy link
Owner

Choose a reason for hiding this comment

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

Ah, gotcha.

@ramkumarmk
Copy link

can render_safe_methods options be added to mute dynamic render path warnings,

render(action => "/application_status/#{find_user(params[:id]).state}", {})

though find_user method is a guard here, the above code raises warning as brakeman couldn't identify it.
It would be nice if I could mention find_user as render_safe_methods in options

@ff-apujari
Copy link

this could not identify the engine path helper and shows it as error

link_to, 'my_engine_path', engine_name.resource_path ...

@tomekr
Copy link

tomekr commented Oct 16, 2015

This check is flagging the following code as a finding:

link_to("Show", current_user.bars.find(params[:id]))

However, this wouldn't allow a user to specify their own protocol and so isn't an actual vulnerability. As a result, I can't really use render_safe_methods in this scenario but I wouldn't want to disable this check completely. What would the recommended course of action be here?

@presidentbeef
Copy link
Owner

@tomekr #742 should address that issue.

@tomekr
Copy link

tomekr commented Oct 17, 2015

@presidentbeef Yep, that did it. Thanks!

Repository owner locked and limited conversation to collaborators Feb 16, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants