Sha256: e0c0891d338415b67b8fcddc012cc5549e56688ea2f648b141178a1b1e6c92a6

Contents?: true

Size: 647 Bytes

Versions: 42

Compression:

Stored size: 647 Bytes

Contents

require 'uri'

# This class is for https://github.com/pact-foundation/pact_broker/issues/101
# curl -i "http://127.0.0.1:9292/<script>"

module Rack
  module PactBroker
    class InvalidUriProtection

      def initialize app
        @app = app
      end

      def call env
        if valid_uri? env
          @app.call(env)
        else
          [404, {}, []]
        end
      end

      def valid_uri? env
        begin
          parse(::Rack::Request.new(env).url)
          true
        rescue URI::InvalidURIError, ArgumentError
          false
        end
      end

      def parse uri
        URI.parse(uri)
      end
    end
  end
end

Version data entries

42 entries across 42 versions & 1 rubygems

Version Path
pact_broker-2.56.1 lib/rack/pact_broker/invalid_uri_protection.rb
pact_broker-2.56.0 lib/rack/pact_broker/invalid_uri_protection.rb
pact_broker-2.55.0 lib/rack/pact_broker/invalid_uri_protection.rb
pact_broker-2.54.0 lib/rack/pact_broker/invalid_uri_protection.rb
pact_broker-2.53.0 lib/rack/pact_broker/invalid_uri_protection.rb
pact_broker-2.52.2 lib/rack/pact_broker/invalid_uri_protection.rb
pact_broker-2.52.1 lib/rack/pact_broker/invalid_uri_protection.rb
pact_broker-2.52.0 lib/rack/pact_broker/invalid_uri_protection.rb
pact_broker-2.51.0 lib/rack/pact_broker/invalid_uri_protection.rb
pact_broker-2.50.1 lib/rack/pact_broker/invalid_uri_protection.rb
pact_broker-2.50.0 lib/rack/pact_broker/invalid_uri_protection.rb
pact_broker-2.49.0 lib/rack/pact_broker/invalid_uri_protection.rb
pact_broker-2.48.0 lib/rack/pact_broker/invalid_uri_protection.rb
pact_broker-2.47.1 lib/rack/pact_broker/invalid_uri_protection.rb
pact_broker-2.47.0 lib/rack/pact_broker/invalid_uri_protection.rb
pact_broker-2.46.0 lib/rack/pact_broker/invalid_uri_protection.rb
pact_broker-2.45.0 lib/rack/pact_broker/invalid_uri_protection.rb
pact_broker-2.44.0 lib/rack/pact_broker/invalid_uri_protection.rb
pact_broker-2.43.0 lib/rack/pact_broker/invalid_uri_protection.rb
pact_broker-2.42.0 lib/rack/pact_broker/invalid_uri_protection.rb