TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 05-20-2009, 08:19 PM   #1 (permalink)
The Contributor
 
Join Date: Apr 2008
Location: Nevada, USA
Posts: 52
Thanks: 10
h0ly lag is on a distinguished road
Default Retaining thread ID when posting reply

I know there are already tons of PHP forums available, but this is just a proof of concept for myself I suppose. So the problem I have is when a user goes to post a reply to a thread, I have an invisible input which post the thread ID to the page I have which enters the reply into the database. The actually problem being that the POST field can be easily manipulated allowing the user to change what thread he/she were actually replying to. Now, with that being said. I could check right before the data is going to be entered if the user has permission to post/read/view that thread or category.

There has to be a better way to do this. How can I retain the thread ID that they're replying too?
__________________
Send a message via AIM to h0ly lag Send a message via MSN to h0ly lag
h0ly lag is offline  
Reply With Quote
Old 05-20-2009, 08:28 PM   #2 (permalink)
The Gregarious
 
allworknoplay's Avatar
 
Join Date: Feb 2009
Location: New York
Posts: 645
Thanks: 64
allworknoplay is on a distinguished road
Default

You know, I've read something about this with a possible solution, I can't recall right now what it was though. Hopefully someone else can chime in....

I'm sure there's a pretty easy solution....
allworknoplay is offline  
Reply With Quote
Old 05-20-2009, 09:55 PM   #3 (permalink)
Wizard
Top Contributor 
 
Village Idiot's Avatar
 
Join Date: Sep 2007
Posts: 1,299
Thanks: 17
Village Idiot is on a distinguished road
Default

Always validate ANY sort of input. vB passes the thread number via GET data, it is still safe because you validate it. Validation would consist of you checking in the database if that user (who should also be authenticated) is indeed the owner of the post.

The rule of thumb is that if it is data from the client side, assume its hostile.
__________________

Village Idiot is offline  
Reply With Quote
Old 05-20-2009, 10:07 PM   #4 (permalink)
La Vida es Sueño
Advanced Programmer Top Contributor 
 
Wildhoney's Avatar
 
Join Date: Sep 2007
Location: Oldham
Posts: 2,280
Thanks: 90
Wildhoney is on a distinguished road
Default

I suppose the first question that springs to mind is why would anybody want to alter the POST ID of the thread they're replying to?

Of course, if they wanted to post a nonsensical response in a random thread, they'd navigate to that thread and post. So as long as you're checking if they have permission to post in that thread, and the thread is valid, where does the problem arise? And what does the so-called master hacker achieve?
__________________
The man who comes back through the Door in the Wall will never be quite the same as the man who went out.
Send a message via AIM to Wildhoney Send a message via MSN to Wildhoney Send a message via Yahoo to Wildhoney
Wildhoney is offline  
Reply With Quote
Old 05-20-2009, 10:12 PM   #5 (permalink)
The Contributor
 
Join Date: Apr 2008
Location: Nevada, USA
Posts: 52
Thanks: 10
h0ly lag is on a distinguished road
Default

Of course, rule number one. Never trust user input. :)

So maybe something like this:
/reply.php?t=56

And all that 't' GET variable would be is the thread ID.

I guess just keep it simple. Just verify and filter the GET var and go with it. Yeah?

EDIT: After read Wildhoney's post, is it more advantageous to use GET or the hidden input field like I currently am? Does it even matter?
__________________
Send a message via AIM to h0ly lag Send a message via MSN to h0ly lag
h0ly lag is offline  
Reply With Quote
Old 05-20-2009, 10:36 PM   #6 (permalink)
The Gregarious
 
allworknoplay's Avatar
 
Join Date: Feb 2009
Location: New York
Posts: 645
Thanks: 64
allworknoplay is on a distinguished road
Default

Quote:
Originally Posted by h0ly lag View Post
Of course, rule number one. Never trust user input. :)

So maybe something like this:
/reply.php?t=56

And all that 't' GET variable would be is the thread ID.

I guess just keep it simple. Just verify and filter the GET var and go with it. Yeah?

EDIT: After read Wildhoney's post, is it more advantageous to use GET or the hidden input field like I currently am? Does it even matter?
I'm not sure it really matters all that much....
allworknoplay is offline  
Reply With Quote
Old 05-20-2009, 10:43 PM   #7 (permalink)
La Vida es Sueño
Advanced Programmer Top Contributor 
 
Wildhoney's Avatar
 
Join Date: Sep 2007
Location: Oldham
Posts: 2,280
Thanks: 90
Wildhoney is on a distinguished road
Default

Nor me. Don't trust the content.

So as long as:
  • It's an integer;
  • It's a valid thread;
  • User has permission to post in the valid thread
__________________
The man who comes back through the Door in the Wall will never be quite the same as the man who went out.
Send a message via AIM to Wildhoney Send a message via MSN to Wildhoney Send a message via Yahoo to Wildhoney
Wildhoney is offline  
Reply With Quote
Old 05-20-2009, 11:38 PM   #8 (permalink)
The Contributor
 
Join Date: Apr 2008
Location: Nevada, USA
Posts: 52
Thanks: 10
h0ly lag is on a distinguished road
Default

Sounds good to me. Oh and is the is_numeric() function sufficient for this?
__________________
Send a message via AIM to h0ly lag Send a message via MSN to h0ly lag
h0ly lag is offline  
Reply With Quote
Old 05-21-2009, 12:03 AM   #9 (permalink)
Wizard
Top Contributor 
 
Village Idiot's Avatar
 
Join Date: Sep 2007
Posts: 1,299
Thanks: 17
Village Idiot is on a distinguished road
Default

Quote:
Originally Posted by h0ly lag View Post
Sounds good to me. Oh and is the is_numeric() function sufficient for this?
Yes


(10 char requirement).
__________________

Village Idiot is offline  
Reply With Quote
Old 05-21-2009, 12:04 AM   #10 (permalink)
The Gregarious
 
allworknoplay's Avatar
 
Join Date: Feb 2009
Location: New York
Posts: 645
Thanks: 64
allworknoplay is on a distinguished road
Default

Quote:
Originally Posted by h0ly lag View Post
Sounds good to me. Oh and is the is_numeric() function sufficient for this?
Yeah that should work.
allworknoplay is offline  
Reply With Quote
Old 05-21-2009, 12:21 AM   #11 (permalink)
La Vida es Sueño
Advanced Programmer Top Contributor 
 
Wildhoney's Avatar
 
Join Date: Sep 2007
Location: Oldham
Posts: 2,280
Thanks: 90
Wildhoney is on a distinguished road
Default

There are ways to also attempt to force an integer. Such as if somebody put in 24a then you could, for instance, typecast that value using (int) and it'd become 24.

However, I wouldn't even bother attempting to purify it. If it's anything other than a number, I would assume they've been fiddling and deny the post.

php Code:
$iNumber = (int) '24a';
var_dump(is_numeric($iNumber)); // True
 
__________________
The man who comes back through the Door in the Wall will never be quite the same as the man who went out.
Send a message via AIM to Wildhoney Send a message via MSN to Wildhoney Send a message via Yahoo to Wildhoney
Wildhoney is offline  
Reply With Quote
Old 05-21-2009, 12:35 AM   #12 (permalink)
The Gregarious
 
allworknoplay's Avatar
 
Join Date: Feb 2009
Location: New York
Posts: 645
Thanks: 64
allworknoplay is on a distinguished road
Default

Quote:
Originally Posted by Wildhoney View Post
There are ways to also attempt to force an integer. Such as if somebody put in 24a then you could, for instance, typecast that value using (int) and it'd become 24.

However, I wouldn't even bother attempting to purify it. If it's anything other than a number, I would assume they've been fiddling and deny the post.

php Code:
$iNumber = (int) '24a';
var_dump(is_numeric($iNumber)); // True
 

1) Shouldn't you be sleeping?


2)I thought var_dump and print_r were used for arrays? I guess you can use it for other things too?
allworknoplay is offline  
Reply With Quote
Old 05-21-2009, 10:50 AM   #13 (permalink)
Orc
The Prestige
 
Orc's Avatar
 
Join Date: Dec 2007
Posts: 1,044
Thanks: 193
Orc is on a distinguished road
Default

Quote:
Originally Posted by allworknoplay View Post
1) Shouldn't you be sleeping?


2)I thought var_dump and print_r were used for arrays? I guess you can use it for other things too?
Mhm, I do it all the time with other data types.
__________________
VillageIdiot can have my babbies ;d
Orc is offline  
Reply With Quote
Old 05-21-2009, 01:27 PM   #14 (permalink)
La Vida es Sueño
Advanced Programmer Top Contributor 
 
Wildhoney's Avatar
 
Join Date: Sep 2007
Location: Oldham
Posts: 2,280
Thanks: 90
Wildhoney is on a distinguished road
Default

Sleeping? Yes, I should!

As for the var_dump. Nooo, I think that is for all data types. Well, that's what I use it for, anyway. I don't use it for arrays though, nor objects. For arrays I use print_r.
__________________
The man who comes back through the Door in the Wall will never be quite the same as the man who went out.
Send a message via AIM to Wildhoney Send a message via MSN to Wildhoney Send a message via Yahoo to Wildhoney
Wildhoney is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Integrating a forum with a membership site? Jmz General 3 12-02-2008 02:19 AM
Domain ideas for my project oscargodson The Lounge 3 09-05-2008 07:27 PM
Building a MySQL search delayedinsanity MySQL & Databases 4 08-14-2008 04:21 AM
Having an issue with the forum.. Tanax Advanced PHP Programming 19 12-24-2007 09:29 AM
Script/Class Ideas? Andrew Absolute Beginners 16 12-13-2007 09:52 AM


All times are GMT. The time now is 05:27 PM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design