Skip to content

Instantly share code, notes, and snippets.

@sevennineteen
Created September 10, 2011 19:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sevennineteen/1208656 to your computer and use it in GitHub Desktop.
Save sevennineteen/1208656 to your computer and use it in GitHub Desktop.
Basic security check to prevent cross-site requests (using Sinatra)
require "rubygems"
require "sinatra"
require "json"
require "haml"
get '/' do
CURRENT_HOST = env['SERVER_NAME'] == 'localhost' ? "#{env['SERVER_NAME']}:#{env['SERVER_PORT']}" : env['SERVER_NAME']
haml :home
end
get '/test_json' do
halt 403, "DENIED: unknown referrer" unless request.referer && request.referer.match(request.host)
return JSON 'test' => 123
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment