Author Topic: method=POST problem (maybe?)  (Read 1180 times)

Offline Sagefire135

  • Level 14
  • *
  • Posts: 107
  • Reputation: +2/-0
    • View Profile
method=POST problem (maybe?)
« on: January 19, 2010, 01:27:30 AM »
Ive been messing around with my pseudo-game and from a players standpoint i like to make things that normally would take a little work....easily done with the push of a button.  While from a coding standpoint, i dont want to allow an "easy button" to get things done, especially since this means a program could be made that would do it automatically. So im thinking about forms and POST vs GET; if i set my form to POST, a player wont be able to see what goes on behind the page. while if i use GET, everything is shown. my thinking led me to realize that it really isnt hard to find out whats going on behind the page via looking at source code.

So if i have a page blahblah.com/action.php that looks something like...
Code: [Select]
<form action="action.php" method="post">
Value 1<input type="text" name="value1">
Value 2<input type="text" name="value2">
<input type="submit" value="Submit">
</form>
a player could easily just paste blahblah.com/action.php?value1=__&value2=__ with the desired info and bookmark it right?

Being curious, i tried this out on a game i play and it just wouldnt work. am i missing something and seeing a problem where one doesnt exist? or is there a way to prevent doing it altogether?

EDIT: Ok i see what i was doing wrong, the submit value needed to be set as well. so i made a simple page with a duplicate of the code that was on the page im looking at, then i directed my page to that one. it worked exactly how i was expecting. So the question now is can it be prevented?
« Last Edit: January 19, 2010, 01:36:10 AM by Sagefire135 »

Offline Bryan

  • Level 7
  • *
  • Posts: 32
  • Reputation: +2/-0
    • View Profile
Re: method=POST problem (maybe?)
« Reply #1 on: January 19, 2010, 01:43:50 AM »
You probably want to look into setting up some form security tokens.  Here's a handy little simplified synopsis of some essentials on PHP and HTML Form Security.

You question seems to be related to -
Quote
CSRF stands for "Cross-Site Request Forgery", and CSRF attacks are similar in scope and methodology to XSS attacks. CSRF attacks usually either exploit the fact that many websites perform actions on HTTP GET requests—deleting blog posts, buying items etc.—or spoof a client request to a resource so that the website believes the request is genuine. Either way, the victim performs an action on a website that trusts him—usually his own—that he did not intend to happen.

Which is generally solved by these two methods-
Quote
The first is rather simple: never, ever use GET for any critical task. Instead, use a POST form. Such requests are harder to forge and have the added bonus that they are impossible to load into HTML image/script tags, eliminating an attacker's ability to exploit your site remotely.

The second is to make sure all requests originate from your own forms, eliminating the possibility that the request could have been loaded from a fake form on a different webpage. To do this, we can create a value— known by some as a "nonce", but here referred to as a "token"—that is created especially for the form, submitted along with it, and checked— along with the usual permission checks—before the action is performed.

Here's an example that creates and checks a token before deleting a forum post:
Code: [Select]
<?php

session_start
();

if( !empty(
$_POST['post_id'] ) {
    if( !
user->is_a_moderator )
        die;
    if( empty(
$_POST['token']) || $_POST['token'] != $_SESSION['token'] )
        die;

    
// All fine: delete the post.
    
delete_postintval($_POST['post_id']) );

    
// Unset the token, so that it cannot be used again.
    
unset($_SESSION['token']);
}

$token md5(uniqid(rand(), true));
$_SESSION['token'] = $token;

?>


<form method="post">

<p>Post ID to delete:</p>
<p><input type="text" name="post_id" /></p>

<input type="hidden" name="token" value="<?php echo $token?>" />

</form>
As we can see, using a POST form with a generated token is simple, straightforward and eliminates the possibility of CSRF attacks.

Lot's more on preventing various common forms of attacks at the link I provided and all over the internet with a few well phrased searches. Happy Coding :)

Offline tellmore

  • Level 12
  • *
  • Posts: 85
  • Reputation: +3/-0
    • View Profile
Re: method=POST problem (maybe?)
« Reply #2 on: January 19, 2010, 01:48:19 AM »
Heh, yes it would be annoying if a form would be bookmarked, GET method does allow that.
Post is better.

There is something else You can try, its easy to make.
Set some hidden fields, and submit them with javascript.
Will not solve all issues, but looks good, and prevents less educated ones to findle with your forms.

Offline Bryan

  • Level 7
  • *
  • Posts: 32
  • Reputation: +2/-0
    • View Profile
Re: method=POST problem (maybe?)
« Reply #3 on: January 19, 2010, 01:49:24 AM »
Relying on client-side authentication?  ???

Offline Sagefire135

  • Level 14
  • *
  • Posts: 107
  • Reputation: +2/-0
    • View Profile
Re: method=POST problem (maybe?)
« Reply #4 on: January 19, 2010, 01:51:59 AM »
ahh nice! cant submit the form unless you know the secret token. which of course would only be known to the code nanoseconds before submiting. very clever.

Offline Nox

  • Level 35
  • **
  • Posts: 738
  • Reputation: +12/-2
    • View Profile
Re: method=POST problem (maybe?)
« Reply #5 on: January 19, 2010, 08:02:42 AM »
as for CSRF - using POST instead of GET doesn't improve security at all... CSRF means that the source form is not from the system itself, so having POST for the attacker only means to change method="get" to method="post" and that's all
Of course generally it's much better to use POST in important cases but I belive this is not really the reason

Tokens are the way.
And yes, never rely on client-side authentication
« Last Edit: January 19, 2010, 08:04:13 AM by Nox »
Meet us at an IRC irc.freenode.net #bbg as well
Enjoy http://spiritbeacon.noxart.cz/ !

Offline JGadrow

  • Level 35
  • **
  • Posts: 1,133
  • Reputation: +23/-2
    • View Profile
Re: method=POST problem (maybe?)
« Reply #6 on: January 20, 2010, 09:31:49 AM »
The awesome benefit of form tokens is that you can create better hidden values. Basically, the form token serves as a unique identifier for a particular form instance. So, you can create a database table like:

form_token, var_name, value

So that you can insert truly hidden data that the client never has access to. For further security, you could tie the form_token to the user session. Meaning that you cannot access the form data from another user's session (as is the intent).
Idiocy - Never underestimate the power of stupid people in large groups.


Offline jannesiera

  • Level 35
  • **
  • Posts: 1,026
  • Reputation: +6/-1
    • View Profile
    • BBGameDesign
Re: method=POST problem (maybe?)
« Reply #7 on: January 20, 2010, 09:55:39 AM »
I don't really get why you should ever use GET... Why do I see people using get all the time, why wouldn't you just always use post?

Offline Harkins

  • Level 28
  • **
  • Posts: 420
  • Reputation: +11/-2
  • Coder, blogger, entrepreneur.
    • View Profile
    • Push CX - Blog
Re: method=POST problem (maybe?)
« Reply #8 on: January 20, 2010, 10:32:26 AM »
Because GET URLs should be idempotent and cacheable. POST is for making changes.

Visit #bbg on irc.freenode.net to talk browser games anytime.

Offline jannesiera

  • Level 35
  • **
  • Posts: 1,026
  • Reputation: +6/-1
    • View Profile
    • BBGameDesign
Re: method=POST problem (maybe?)
« Reply #9 on: January 20, 2010, 10:39:11 AM »
Because GET URLs should be idempotent and cacheable. POST is for making changes.

Ah, I see. Now gotta remember it :D.

 


SimplePortal 2.3.3 © 2008-2010, SimplePortal