Skip to content

Added option to check that request comes from same origin #36

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions proxy.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

/**
* Enables or disables checking that HTTP_REFERRER and HTTP_HOST have the same hostname.
* Recommended value: false for public CORS proxy, true for private CORS proxy
*/
define('CSAJAX_SAME_ORIGIN_ONLY', false);

/**
* Enables or disables filtering for cross domain requests.
* Recommended value: true
Expand Down Expand Up @@ -61,6 +67,24 @@

/* * * STOP EDITING HERE UNLESS YOU KNOW WHAT YOU ARE DOING * * */

// check for same origin
if (CSAJAX_SAME_ORIGIN_ONLY) {
if (isset($_SERVER['HTTP_REFERER']) && isset($_SERVER['HTTP_HOST']) && isset($_SERVER['REQUEST_SCHEME'])) {
$p_referrer_url = parse_url($_SERVER['HTTP_REFERER']);
if ($p_referrer_url['host'] != $_SERVER['HTTP_HOST']) {
csajax_debug_message('Referrer hostname is not same origin');
exit;
}
if ($p_referrer_url['scheme'] != $_SERVER['REQUEST_SCHEME']) {
csajax_debug_message('Referrer hostname is same origin, not same scheme');
exit;
}
} else {
csajax_debug_message('Cannot verify same origin without HTTP_REFERER, HTTP_HOST, REQUEST_SCHEME');
exit;
}
}

// identify request headers
$request_headers = array( );
foreach ($_SERVER as $key => $value) {
Expand Down