Jump to content

Best Way To Bounce Users Without Getting XSSed


neoform

Recommended Posts

I have a login script that needs to be able to send the user back to where they were before logging in..

 

right now I'm using

login.php?b=previous_page.php

but this leaves me open for abuse from malicious links..  what would be the best way to protect from this sort of thing? I thought about cookies, but i'm not sure how i'd pull that off since i'd have to set a 'referral' cookie on virtually every page for it to know where to go back..

Link to comment
Share on other sites

I don't know if this is the best way, here is what I am using at the moment to stop most of it,

 

<?php
$num_m = preg_match("[href|</A>|</a>|<]",  $_SERVER['QUERY_STRING'], $z1, PREG_OFFSET_CAPTURE);
if($num_m >= 1){
exit();
}
?>
//Rest of page in new <?php ?> brackets

 

I will keep adding stuff to the match as it besomes clear, but I think that should catch most of it.

Link to comment
Share on other sites

header("Location: ".$_SERVER['HTTP_REFERER']);

 

that wont work if the page they're coming from is an action or something.. or if you actually want them to bounce to a different page.. :S

 

like to track outgoing clicks or something.. (just generalizing, but i'm looking for the most versatile method)

Link to comment
Share on other sites

i think i'mma use this:

 

function make_bounce($url = '')
{
if (isset($_SERVER['HTTP_REFERER']) && ! $url) 
	$url = $_SERVER['HTTP_REFERER'];
make_cookie('bounce', rawurlencode($url));
}

function bounce_user()
{
$url = isset($_COOKIE['bounce']) ? rawurldecode($_COOKIE['bounce']) : '';
kill_cookie('bounce');
if ($url)
	header('Location: '.$url);
}

unless someone sees a problem with this sorta method..

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.