Skip to content

url()->previousPath() potentially returns url #57456

@garygreen

Description

@garygreen

Laravel Version

12.x

PHP Version

8.2

Database Driver & Version

No response

Description

The url()->previousPath() function is intended to return the path of the previous url - this is derived from the referer header from the url()->previous() function. As the client sends the referer header, it is untrustworthy and it can be different from the apps url, which it is assumed to always be.

This can be simulated like so:

// assuming config('app.url') is `https://myapp.local/`

// client could technically send whatever referer
request()->headers->set('referer', 'http://www.google.com/blah');

// unexpected full url, not path
dd(url()->previousPath()); // "http://www.google.com/blah"

// expected: "/blah", or possibly exception?

This is possibly a security vulnerability if developers expect previousPath() to not only return paths, but also restrict it from returning if the url is different to the apps one.

Steps To Reproduce

--

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions