Jump to content
MakeWebGames

Preg_Match Help :-) Security Fix for Viewuser hack.


Recommended Posts

Posted

Ok, so I've got a few ways that "works" to stop the viewuser/preferance hack.

I had a thought on "another" way to do this and I am garbage with preg

So any help would be beneficial to anyone :P

Ok, so instead of using getimagesize on the displaypicture bit, which occasionally bugs certain images.

What if in the following link, you do something like... if ($r['display_pic'] preg match .php/.exe etc) { echo fail } else yadda yadda.

Would that be do-able?

If so...how? :P

 

if($r['display_pic']) { $pic = "{$r["; } else { $pic = "This user has no display pic!"; }

Posted

yea we've just discussed that in chat, meh.

i was already using getimagesize >,<

 

So I beleive this should do it, thanks

 

if(preg_match("/^.*\.(jpg|jpeg|png|gif)$/i", $r['display_pic'])) 
{    
if(@getimagesize($r['display_pic'])) 
{    
$pic = "[img={$r[]";
}
}

else 
{ 
$pic = "This user has no display pic!"; 
}
Posted

Yup that was an interesting chat even though I missed it (too busy chatting elsewhere xD ) but yeah allowing them to upload was a suggestion also you may wan't to think about that one

*Directed at all*

Posted
Yup that was an interesting chat even though I missed it (too busy chatting elsewhere xD ) but yeah allowing them to upload was a suggestion also you may wan't to think about that one

*Directed at all*

Well.. My site dosen't "upload" the image but instead captures the image into various sizes onto my webserver to make pulling the image up quicker and then also extra security. Considering im using the GD library to create the image.. You pass some PHP through that and call it an image it will just give you a black display pic.
Posted

After trying several differant approaches this is the one that has succeeded over all

 

if(!@getimagesize($ir['display_pic']))
{
$pic ="images/default.png' width='43' height='43' border='0'";
}
elseif(@getimagesize($ir['display_pic']))
{
$pic = $ir['display_pic'];
}
Posted

Dave didn't i error your display image?

 

 if(preg_match("/^.*\.(jpg|jpeg|png|gif)$/i", $r['display_pic'])) {    
  if ( is_array(@getimagesize($r['display_pic'])) ) {    
  $pic = "[img={$r[]";
  }
 } else { 
  $pic = "This user has no display pic!"; 
 }

If you had listened to mdshare when he mentioned getimagesize first time round you may have easily avoided this entire thread.

Posted
Dave didn't i error your display image?

 if(preg_match("/^.*\.(jpg|jpeg|png|gif)$/i", $r['display_pic'])) {    
  if ( is_array(@getimagesize($r['display_pic'])) ) {    
  $pic = "";
  }
 } else { 
  $pic = "This user has no display pic!"; 
 }

If you had listened to mdshare when he mentioned getimagesize first time round you may have easily avoided this entire thread.

You did :) and that's how I fixed it :L If that didn't work I was going to start checking the mime type haha :L
  • 3 months later...
Posted

Just a quick note to help anyone who had the same problem as me.

If you used the @getimagesize() function and you sure you were correct with the coding, but any picture you uploaded (or are uploading if used in preferences.php) never returned properly, you may have to enable allow_url_fopen in your php.ini.

No matter what,any picture I was uploading, it always evaluated to false which would show an error to the user. Changing the allow_url_fopen to "on" made it work.

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.   Paste as plain text instead

  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...