Skip to content

Redirects

rn_forge.auth.redirects

Validation of the post-login return_to target.

InvalidReturnTo(reason)

Bases: AppException

A return_to value is not an allowed relative path.

Callers catch it and fall back to a default target.

Parameters:

Name Type Description Default
reason str

A short description of the rule the value broke.

required

check(value, message, *message_args, **kwargs) classmethod

Raise this exception if value is falsy.

Parameters:

Name Type Description Default
value Any

The value to test.

required
message str

Exception message (supports positional format args).

required
*message_args Any

Forwarded to message.format().

()
**kwargs Any

Forwarded as error_code / error_data to the constructor.

{}

Example::

AppException.check(path.exists(), "Missing file: {}", path, error_code=404)

validate_return_to(value, *, prefixes)

Return value when it is a relative path under one of prefixes.

A prefix matches whole path segments: /app allows /app and /app/x but not /apple, and / allows every path. A query string or fragment may follow the path.

Parameters:

Name Type Description Default
value str

The candidate target.

required
prefixes Sequence[str]

Allowed path prefixes, each starting with /.

required

Returns:

Type Description
str

value, unchanged.

Raises:

Type Description
InvalidReturnTo

value is empty, is not a path starting with a single /, contains a backslash or a control character, has a percent- encoded slash, backslash or dot in its path, has a .. segment, or lies outside every prefix.