Test Your Protection Against Hijacking

As we discussed in previous chapters, an important part of keeping your scripts secure is to test them for protection against possible vulnerabilities.

Here we present a sample of such a test, in this case testing whether the technique of hashing really works. This code can be found also as hashTest.php in the Chapter 6 folder of the downloadable archive of code for Pro PHP Security at http://www.apress.com.

<?php // create a temporary file $tempname = '/tmp/mytestfile'; $tempfile = fopen( $tempname, 'w+' ); fwrite( $tempfile, 'hello\n' ); fclose( $tempfile ); // attempt to protect from hijacking by hashing the file contents $hash = sha1_file( $tempname ); ///////////////////////////// // attempt to ...

Get Pro PHP Security: From Application Security Principles to the Implementation of XSS Defenses, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.