GithubHelp home page GithubHelp logo

Comments (5)

georgeu2000 avatar georgeu2000 commented on June 9, 2024

I wrote a fix for it. Should I add it to rack-protection?

module Rack
  class RefererFix
    def initialize app
      @app = app
    end

    def call env
      fix env

      @app.call( env ) # Response not modified.
    end

    def fix env
      env[ 'HTTP_REFERER' ].gsub!( '|', '' ) if env[ 'HTTP_REFERER' ]
    end
  end
end


describe Rack::RefererFix do
  let( :inner_app ) do
    lambda{ |env| [200, env, [ 'All good!' ]]}
  end
  let( :app         ){ Rack::RefererFix.new(inner_app) }

  let( :invalid_uri ){ 'http://www.example.com/invalid|uri'     }
  let( :valid_uri   ){ 'http://www.example.com/invaliduri'      }
  let( :headers     ){{ 'HTTP_REFERER' => invalid_uri          }}

 before do
    get '/', {}, headers
  end

  it 'fixes invalid referer' do
    last_response.headers[ 'HTTP_REFERER' ].should == valid_uri
  end

  context 'when valid referer' do
    let( :headers ){{ 'HTTP_REFERER' => valid_uri }}

    it 'does not change' do
      last_response.headers[ 'HTTP_REFERER' ].should == valid_uri
    end
  end

  context 'when nil referer' do
    let( :headers ){{ 'HTTP_REFERER' => nil }}

    it 'does not raise error' do
      last_response.status.should == 200
    end
  end

  context 'when empty referer' do
    let( :headers ){{ 'HTTP_REFERER' => '' }}

    it 'does not raise error' do
      last_response.status.should == 200
    end
  end
end

from rack-protection.

rkh avatar rkh commented on June 9, 2024

Yes, PR would be very welcome.

from rack-protection.

metcalf avatar metcalf commented on June 9, 2024

We're seeing occasional exceptions from this in production as well. Would be great to have the fix!

from rack-protection.

rkh avatar rkh commented on June 9, 2024

I'll ship a release with the fix soon.

from rack-protection.

zzak avatar zzak commented on June 9, 2024

Fix should already be in v1.5.3 according to 6d953d2

from rack-protection.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.