PDA

View Full Version : Is this safe?


DeadlySin3
11-17-2002, 08:02 PM
<html>
<head>
<title>removing lines from a file</title>
</head>

<body>

<?php

// this function strips a specific line from a file
// if no linenumber is specified, last line is stripped
// if a line is stripped, functions returns True else false
//
// e.g.
// cutline('foo.txt'); // strip last line
// cutline('foo.txt',1); // strip first line


if ( isset( $admin ) ) {
require("variables.php");
function cutline($filename,$line_no=-1) {

$strip_return=FALSE;

$data=file($filename);
$pipe=fopen($filename,'w');
$size=count($data);

if($line_no==-1) $skip=$size-1;
else $skip=$line_no-1;

for($line=0;$line<$size;$line++)
if($line!=$skip)
fputs($pipe,$data[$line]);
else
$strip_return=TRUE;

return $strip_return;
}

cutline('$testdoc',$deltag); // defined in variables.php
}
?>

<?php if ( isset( $admin ) ) { echo "Tag number $deltag has been deleted!"; }
else { echo "You need to <a href=\"adminIn.php\">login</a> before you can delete tags"; } ?>
<?php if ( isset( $admin ) ) { echo "<a href=\"javascript:history.back(1)\"> go back</a>"; } ?>

</body>
</html>


I found this lil bit of code while surfing the net - I set up a test tagboard, posted about 20 tags, and went through and picked lines to delete randomly. It works - but my question is, is it safe?

iDxMan
11-18-2002, 12:10 AM
What does $admin get set to if they are correctly logged in? (0/1 true/false?) Initial paranoia says be careful if register_globals is on. The user may just have to append ?admin=1 to the script, then they're in.

-r

DeadlySin3
11-18-2002, 12:31 AM
Well, thats always good to know - but I have $admin set to a rather long word, mixed w/letters & numbers.

btw - appending "?admin=1" to the script right now, brings me back to the login page, which in turn, sets a cookie w/the var $admin in it, blank, with an expiry time of 60 seconds ago. :D

roninblade
11-18-2002, 04:28 AM
i guess idxman is saying you should always code for register_globals off. that way it works for both configurations, plus it removes that security loop hole. besides, php now comes with the register_globals off as the default.

if you're using cookies you can maybe put the line $admin = $_COOKIE['admin']; at the top of your page so you dont have to edit the rest of the lines below.