$_POST array question

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Jerry Stuckle

    #16
    Re: $_POST array question

    William Gill wrote:
    William Gill wrote:
    >Jerry Stuckle wrote:
    >>William Gill wrote:
    ><snip>
    >>>I don't. I didn't want to perform an array_key_exist s( 'fieldname',
    >>>$_POST ) before I test what value they contain.
    >>>>
    >>>>
    >>>
    >>Use isset($_POST['fieldname']).
    >>>
    >That's what I meant, array_key_exist s wouldn't help.
    >
    isset() seems to be a waste of time also, since every field is being set
    even if only with an empty string.
    >
    But every field does NOT necessarily need to be set. For instance, a
    hacker could create a page which links to yours and doesn't have those
    fields set.

    NEVER, NEVER, NEVER trust user input!

    --
    =============== ===
    Remove the "x" from my email address
    Jerry Stuckle
    JDS Computer Training Corp.
    jstucklex@attgl obal.net
    =============== ===

    Comment

    • William Gill

      #17
      Re: $_POST array question

      Jerry Stuckle wrote:
      >
      But every field does NOT necessarily need to be set. For instance, a
      hacker could create a page which links to yours and doesn't have those
      fields set.
      >
      NEVER, NEVER, NEVER trust user input!
      >
      I use a session variable to reject input from any other page.
      if ($_SESSION['secret'] != $_POST['secret'])

      Besides, I fail to see where an unset field poses a threat. One set
      with an unsafe value does, which is why I filter/validate IT not the key.

      Am I missing something here?

      Comment

      • Guillaume

        #18
        Re: $_POST array question

        William Gill a écrit :
        I use a session variable to reject input from any other page.
        if ($_SESSION['secret'] != $_POST['secret'])
        And what prevents the hacker from looking at your HTML output to read
        the "secret" variable, then parse through your site to generate the
        session (without validating the site's form), and finally validate his
        own HTML form on his local computer (which "action" would be the same as
        the site's one) with the opened session he has with your server ?
        Besides, I fail to see where an unset field poses a threat. One set
        with an unsafe value does, which is why I filter/validate IT not the key.
        Simple example: an empty password is a threat.
        Maybe not your case, but it's a trivial example coming to my mind,
        meaning there could be many more example, not as trivial, but that would
        create (huge or not) security holes.

        Regards,
        --
        Guillaume

        Comment

        • Guillaume

          #19
          Re: $_POST array question

          Guillaume a écrit :
          William Gill a écrit :
          >Besides, I fail to see where an unset field poses a threat. One set
          >with an unsafe value does, which is why I filter/validate IT not the key.
          Simple example: an empty password is a threat.
          Maybe not your case, but it's a trivial example coming to my mind,
          meaning there could be many more example, not as trivial, but that would
          create (huge or not) security holes.
          I should precise: unset field means $_POST['field'] would be empty and
          generate an empty string.
          Thus unset field may lead to unset value which was my point.

          While your check script may check for the value "if set", and never deal
          with the non-submitted values that still may be parsed through your code.
          Well I admit it would be quite uncommon, but hackers love uncommon bugs :p

          --
          Guillaume

          Comment

          • William Gill

            #20
            Re: $_POST array question

            Guillaume wrote:
            William Gill a écrit :
            >I use a session variable to reject input from any other page.
            > if ($_SESSION['secret'] != $_POST['secret'])
            And what prevents the hacker from looking at your HTML output to read
            the "secret" variable, then parse through your site to generate the
            session (without validating the site's form), and finally validate his
            own HTML form on his local computer (which "action" would be the same as
            the site's one) with the opened session he has with your server ?
            $secret is not a static value it's generated using a random number
            algorithm when the session starts, and expires when the session expires.

            >Besides, I fail to see where an unset field poses a threat. One set
            >with an unsafe value does, which is why I filter/validate IT not the key.
            Simple example: an empty password is a threat.
            Maybe not your case, but it's a trivial example coming to my mind,
            meaning there could be many more example, not as trivial, but that would
            create (huge or not) security holes.
            I validate every field's submitted value, even if a hacker got one in,
            it wouldn't meet muster. The original question related to checking to
            see if the field was set, which apparently it always is, even when empty.

            I'm not trying to be argumentative, I am really trying to be sure what
            I'm doing is what I think.

            Comment

            • William Gill

              #21
              Re: $_POST array question

              Guillaume wrote:
              I should precise: unset field means $_POST['field'] would be empty and
              generate an empty string.
              Thus unset field may lead to unset value which was my point.
              >
              While your check script may check for the value "if set", and never deal
              with the non-submitted values that still may be parsed through your code.
              Well I admit it would be quite uncommon, but hackers love uncommon bugs :p
              If my code doesn't do anything with unexpected fields, or empty strings,
              or treats them as invalid entries, what is the threat?

              Comment

              • Guillaume

                #22
                Re: $_POST array question

                William Gill a écrit :
                Guillaume wrote:
                >William Gill a écrit :
                >>I use a session variable to reject input from any other page.
                >> if ($_SESSION['secret'] != $_POST['secret'])
                >And what prevents the hacker from looking at your HTML output to read
                >the "secret" variable, then parse through your site to generate the
                >session (without validating the site's form), and finally validate his
                >own HTML form on his local computer (which "action" would be the same
                >as the site's one) with the opened session he has with your server ?
                $secret is not a static value it's generated using a random number
                algorithm when the session starts, and expires when the session expires.
                Yep but to "POST" this value (since you get back a $_POST variable), it
                must be included in the form, thus visible through the HTML source code.
                Anybody can check your *HTML* source and get back that hidden field to
                recreate it.

                Then, anybody can create a .html file on his/her computer, recreate the
                form with the required field, include the hidden input with the secret
                value seen in the source, and post it as is, using for example a second
                tab in firefox (having *your* form opened in the first tab means you
                created the session, validating anything on the same server on a second
                tab use the same session - this is not the case if you open a second
                browser which would be a second process).

                I did it not so far ago, when registering to a website where the
                username on the forum could be specified but had to have at least 6
                chars. I wanted to use 4, and the site was checking the length with a
                (stupid) JavaScript. I recreated the form, removing the JS check, and
                submitted it. Worked like a charm (and the admins never noticed the
                length - or should I say they didn't care, since they knew me).

                To secure that, you *could* check for the HTTP_REFERER being only your
                server, but it also can be faked...

                IMO, you can't reject input from any other page, you can just parse the
                input and validate them all.

                --
                Guillaume

                Comment

                • William Gill

                  #23
                  Re: $_POST array question

                  Guillaume wrote:
                  >
                  To secure that, you *could* check for the HTTP_REFERER being only your
                  server, but it also can be faked...
                  I was under the impression HTTP_REFERER was less reliable. I read
                  somewhere some browsers don't set it.
                  IMO, you can't reject input from any other page, you can just parse the
                  input and validate them all.
                  >
                  Which is what I do. I got in the habit years ago of checking to see if
                  the field was set first, but PHP always sets it, so why bother.



                  Comment

                  Working...