This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| module Rack | |
| # | |
| # RefererControl is a Rack middleware app which restricts access to paths | |
| # based on the Referer header. Using RefererControl you can make sure | |
| # users follow the intended flow of a website. If a controlled path is | |
| # visited with an unacceptable Referer URI, then a simple 307 Redirect | |
| # response is returned. | |
| # | |
| # RefererControl should also make Cross Site Request Forgery (CSRF) a | |
| # little more difficult to exploit; but not impossible using JavaScript. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| module Rack | |
| class GoogleAnalytics | |
| TRACKING_CODE = <<-EOCODE | |
| <script type="text/javascript"> | |
| var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www."); | |
| document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E")); | |
| </script> | |
| <script type="text/javascript"> | |
| try { | |
| var pageTracker = _gat._getTracker("{{ID}}"); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| module Rack | |
| class NoIE | |
| def initialize(app, options = {}) | |
| @app = app | |
| @options = options | |
| @options[:redirect] ||= 'http://www.microsoft.com/windows/internet-explorer/default.aspx' | |
| @options[:minimum] ||= 7.0 | |
| end | |
| def call(env) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require "net/http" | |
| # Example Usage: | |
| # | |
| # use Rack::Proxy do |req| | |
| # if req.path =~ %r{^/remote/service.php$} | |
| # URI.parse("http://remote-service-provider.com/service-end-point.php?#{req.query}") | |
| # end | |
| # end | |
| # |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Temporary middleware for your APIs to immediately support a /v1/some/path.json prefix to | |
| # all route calls. | |
| # | |
| # When you decide to freeze a current API and provide a /v2/ route then | |
| # you will cease using this middleware and implement /v1/ and /v2/ routing as appropriate | |
| # to your app. | |
| # | |
| # This middleware provides a placeholder until then so users can be told to use /v1/some/path routes | |
| # immediately. | |
| # |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| module Rack | |
| class ZombieShotgun | |
| ZOMBIE_AGENTS = [ | |
| /FrontPage/, | |
| /Microsoft Office Protocol Discovery/, | |
| /Microsoft Data Access Internet Publishing Provider/ | |
| ].freeze | |
| ZOMBIE_DIRS = ['_vti_bin','MSOffice','verify-VCNstrict','notified-VCNstrict'].to_set.freeze |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Rack::ResponseTimeInjector | |
| def initialize(app, options = {}) | |
| @app = app | |
| @format = options[:format] || "%f" | |
| end | |
| def call(env) | |
| t0 = Time.now | |
| returning @app.call(env) do |response| | |
| response.last.body.gsub! /\$responsetime(?:\((.+)\))?/ do |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require 'net/http' | |
| class ServerProxy | |
| def self.call(env) | |
| if env["PATH_INFO"] =~ /^\/server_proxy/ | |
| request = Rack::Request.new(env) | |
| params = request.params | |
| Net::HTTP.start(params["service_url"]) {|http| | |
| req = Net::HTTP::Get.new(params["service_path"]) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| module Rack | |
| class ChromeFrame | |
| def initialize(app, options={}) | |
| @app = app | |
| end | |
| def call(env) | |
| status, headers, response = @app.call(env) | |
| if env['HTTP_USER_AGENT'] =~ /MSIE/ && response.content_type == 'text/html' |