Skip to content

Form nonce (CSRF token) is generated but never checked #400

Closed

Description

@caseysoftware

Forms add a token with w2p_Output_HTML_FormHelper::addNonce(), and the docs page on security nonces says w2p_Controllers_Base validates it. It doesn't: the check in classes/w2p/Controllers/Base.class.php has an empty body, and its comment says it would be turned on in v4.0:

if (('' != $AppUI->__nonce) && ($AppUI->__nonce != $myArray['__nonce'])) {
}

So none of the forms that save or delete through w2p_Controllers_Base are protected against cross-site request forgery. Most other do_*_aed.php controllers don't check a token at all.

The token is also weak if it were checked: it is md5(time() . implode($user_prefs)), so it is predictable, and only the most recently generated one is kept, so a second open form invalidates the first.

Fix:

  • Generate the token with random_bytes(), keep it per session (or per form), and compare with hash_equals().
  • Reject the request in w2p_Controllers_Base::process() when the token is missing or wrong.
  • Add the same check to the controllers that don't use w2p_Controllers_Base, and make sure every form that changes data calls addNonce().
  • Change state-changing GET links (such as logout and ending sessions) to POST.

Mentioned in the Security Notes' known limitations for the logout links only; this is wider.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions