Re: Session token



On Fri, 03 Oct 2008 21:04:41 +0200, Lan Mind <LANMIND01@xxxxxxxxx> wrote:

Hello again everybody,

My page: http://www.dockhawk.com/

I'm trying to implement some "session security" PHP script
mentioned in the "Cross-site request forgery" section of this
tutorials (pdf): http://daniel0.net/phpfreaks_tutorials/php_security/php_security.pdf

1) Never, never, never use a GET for an alteration, GET is for presentation of data, possibly you can do some statistical logging, but that's it.
2) If you're still concerned about unknowingly posting (instead of getting) from another site, you can (besides of course making the session cookie httponly) add a temporary hidden post value in your 'alteration form', in the form of a random string which is whitelisted in your current session. On a request, refuse to do an action if the hash doesn't match the current (or one of the several) whitelisted strings.

Of course, you employ other security measures as using HTTPS instead of HTTP, etc. etc.

I was trying to figure out if it was functioning by putting a value in
the hidden input that won't be equal to the session token. The hidden
input is in my default.html page inside the <div id="search_form">.

So as the value is wrong the PHP should return "Invalid Token" but
it's not. In earlier testing I had taken away the not "!" in the PHP
and left the hidden input's value as "<?php echo $_SESSION['token'] ?
" and the PHP did return "Invalid Token" as it should have.

It seems the "!" isn't working, I'm not sure. Thank you for your time,
here is the PHP:

<?php

Perhaps a missing:
session_start();

(var_dump($_GET,$_SESSION); when in doubt)

.... and if so, when concerned with security, I sincerely hope you _check_ the $_SESSION for a valid login on _every_ page?

if ($_GET['token'] !== $_SESSION['token']) {
die('Invalid token');

}

This function we usually call htmlspecialchars($string,ENT_QUOTES);

function parseToXML($htmlStr)
{
$xmlStr=str_replace('<','&lt;',$htmlStr);
$xmlStr=str_replace('>','&gt;',$xmlStr);
$xmlStr=str_replace('"','&quot;',$xmlStr);
$xmlStr=str_replace("'",'&#39;',$xmlStr);
$xmlStr=str_replace("&",'&amp;',$xmlStr);
return $xmlStr;

}


And I can't see a further creation of the $_GET variable in any URL the user will visit (link, target, etc.), so there's no way of knowing for us wether there's a fault there.
--
Rik Wasmus
.



Relevant Pages

  • getting PHP5 sessions working when browser doesnt accept cookies.
    ... Here is my PHP ... The brower URL does not contain the session ID ... A warning appears if the specified function is not defined, ... support by the security team. ...
    (php.general)
  • session trouble
    ... everything else considering PHP is working perfectly and as far as I see ... the session tmp file is created in my tmp dir and I really don't see a valid ... A warning appears if the specified function is not defined, ... Setting certain environment variables may be a potential security breach. ...
    (alt.php)
  • Re: Looking for general advice on security
    ... PHP pages have to be world-readable, ... SSL provides a way for a thief with a browser to communicate with ... cookies because the user can't fake a session with arbitrary contents, ... Try to send a message to the user and see if the mail server ...
    (comp.lang.php)
  • Re: query string passing woes........ help... please....
    ... |> | offer any help other than saying that my validation could be FAR more ... I'm a total newbie at php. ... The easiest way for you would be to make the html form called form.php ... $_SESSION array using the same names. ...
    (alt.php)
  • [REVS] PHP 4.1.0 Integrates Much Needed Security Features
    ... The following security advisory is sent to the securiteam mailing list, and can be found at the SecuriTeam web site: http://www.securiteam.com ... the user provided input from any malicious content, allowing secure PHP ... While it is quite possible to write secure code in PHP, PHP's developers ... * $_SESSION - contains HTTP variables registered by the session module ...
    (Securiteam)