Skip to content

Instantly share code, notes, and snippets.

@thewhodidthis
Last active January 5, 2021 23:03
Show Gist options
  • Save thewhodidthis/97930d5230adba5788a90421c92b2d73 to your computer and use it in GitHub Desktop.
Save thewhodidthis/97930d5230adba5788a90421c92b2d73 to your computer and use it in GitHub Desktop.
Simple CORS bypass
<?php
$url = filter_input(INPUT_GET, 'url', FILTER_SANITIZE_URL) or exit;
// This allows for catching warnings eg. when offline, or `$url` resource missing
set_error_handler(
function ($severity, $message, $file, $line) {
if (error_reporting() & $severity) {
throw new ErrorException($message, 0, $severity, $file, $line);
}
}
);
try {
$content = file_get_contents($url, 0);
if (false !== $content) {
echo $content;
}
} catch (Exception $e) {
http_response_code(500);
}
// Back to normal
restore_error_handler();
#!/usr/bin/env ruby
require 'open-uri'
require 'cgi'
require 'webrick'
server = WEBrick::HTTPServer.new(
:Port => 9090,
)
server.mount_proc '/proxy' do |req, res|
params = CGI.parse(req.query_string)
target = params['url'].first
# TODO: Wrap in try block?
feed = URI.open(target)
res.header["Access-Control-Allow-Origin"] = "*"
res.header["Content-Type"] = feed.content_type
res.body = feed.read
end
server.start
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment