Skip to content

Open redirect via unvalidated wantsurl parameter after successful authentication #49

Description

@Ewa55

After a successful Basic authentication, the plugin reads the wantsurl parameter directly from $_GET and passes it to redirect() without validating that it is a local URL.

Location:
File: auth/basic/auth.php

Current code:
...
} else if (isset($_GET['wantsurl'])) {
$urltogo = $_GET['wantsurl'];
}
...
redirect($urltogo);

This allows an attacker to craft a login URL such as:

https://moodle.example.com/login/index.php?wantsurl=https://evil.example

After successful authentication, the user is redirected to the attacker-controlled website.

Expected behaviour:
The redirect target should be validated and restricted to local Moodle URLs.

RECOMMENDED FIX:
$rawurl = optional_param('wantsurl', '', PARAM_LOCALURL);
if ($rawurl !== '') {
$urltogo = $rawurl; // PARAM_LOCALURL strips external hosts
}

This prevents open redirect attacks while preserving the intended functionality.

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