Skip to content

JSP with CSRF Guard form tag having an action with query parameters fails validation #287

@Frank-St

Description

@Frank-St

Using version 4.3.0-jakarta of OWASP CSRF Guard.

When using TokenPerPage = true, the CSRF Guard form tag for JSPs creates a page token for the page using the attribute value of the action attribute of the form. If this attribute contains query parameters - e. g. it has the value MyServlet?a=b -, these are included in the page URL in the token map. When validating the CSRF token, however, the code tries to get the token using the HttpServletRequest.getRequestURI() method which omits the query string, e. g it uses only MyServlet in this case to get the page token. Hence no matching token is found and the validation fails.

Workaround is to set TokenPerPage=false.

To fix the bug, the query string should be removed from the action attribute value before using it as the key for the page specific token map.

Related, but another issue: It is valid HTML to omit the action attribute. In this case, the form is posted to the URL from where the form was loaded. Hence, it would be nice to use the current document URL as the page if there is no action attribute in a form. Currently, the form tag just throws an NPE in this case.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions