Merge commit from fork
This commit is contained in:
1 parent
d4e4c9669d
commit
b3e9b3351b
3 files changed
+24
-2
No files matched your search
@@ -7,14 +7,21 @@ import { Anchor, Button, Card, Code, Collapse, Divider, PasswordInput, Stack, Te
|
|||||||
import { useDisclosure } from "@mantine/hooks";
|
import { useDisclosure } from "@mantine/hooks";
|
||||||
import { z } from "zod/v4";
|
import { z } from "zod/v4";
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
import { signIn } from "@homarr/auth/client";
|
import { signIn } from "@homarr/auth/client";
|
||||||
import { revalidatePathActionAsync } from "@homarr/common/client";
|
import { revalidatePathActionAsync } from "@homarr/common/client";
|
||||||
import type { useForm } from "@homarr/form";
|
import type { useForm } from "@homarr/form";
|
||||||
import { useZodForm } from "@homarr/form";
|
import { useZodForm } from "@homarr/form";
|
||||||
import { showErrorNotification, showSuccessNotification } from "@homarr/notifications";
|
import { showErrorNotification, showSuccessNotification } from "@homarr/notifications";
|
||||||
import { useScopedI18n } from "@homarr/translation/client";
|
import { useScopedI18n } from "@homarr/translation/client";
|
||||||
|
import { sanitizeRedirectionUrl } from "@homarr/validation/redirection-url";
|
||||||
import { userSignInSchema } from "@homarr/validation/user";
|
import { userSignInSchema } from "@homarr/validation/user";
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
type Provider = "credentials" | "ldap" | "oidc";
|
type Provider = "credentials" | "ldap" | "oidc";
|
||||||
|
|
||||||
interface LoginFormProps {
|
interface LoginFormProps {
|
||||||
@@ -70,7 +77,7 @@ export const LoginForm = ({ providers, oidcClientName, isOidcAutoLoginEnabled, c
|
|||||||
|
|
||||||
// Redirect to the callback URL if the response is defined and comes from a credentials provider (ldap or credentials). oidc is redirected automatically.
|
// Redirect to the callback URL if the response is defined and comes from a credentials provider (ldap or credentials). oidc is redirected automatically.
|
||||||
await revalidatePathActionAsync("/");
|
await revalidatePathActionAsync("/");
|
||||||
router.push(callbackUrl);
|
router.push(sanitizeRedirectionUrl(callbackUrl));
|
||||||
},
|
},
|
||||||
[t, router, callbackUrl],
|
[t, router, callbackUrl],
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import { getScopedI18n } from "@homarr/translation/server";
|
|||||||
|
|
||||||
import { HomarrLogoWithTitle } from "~/components/layout/logo/homarr-logo";
|
import { HomarrLogoWithTitle } from "~/components/layout/logo/homarr-logo";
|
||||||
import { LoginForm } from "./_login-form";
|
import { LoginForm } from "./_login-form";
|
||||||
|
import { sanitizeRedirectionUrl } from "@homarr/validation/redirection-url";
|
||||||
|
|
||||||
interface LoginProps {
|
interface LoginProps {
|
||||||
searchParams: Promise<{
|
searchParams: Promise<{
|
||||||
@@ -19,7 +20,7 @@ export default async function Login(props: LoginProps) {
|
|||||||
const session = await auth();
|
const session = await auth();
|
||||||
|
|
||||||
if (session) {
|
if (session) {
|
||||||
redirect(searchParams.callbackUrl ?? "/");
|
redirect(sanitizeRedirectionUrl(searchParams.callbackUrl));
|
||||||
}
|
}
|
||||||
|
|
||||||
const t = await getScopedI18n("user.page.login");
|
const t = await getScopedI18n("user.page.login");
|
||||||
|
|||||||
@@ -0,0 +1,14 @@
|
|||||||
|
/**
|
||||||
|
* Sanitizes the URL from malicious payloads.
|
||||||
|
* Prevents open redirects such as //example.com/path
|
||||||
|
* and prevents XSS such as javascript:().
|
||||||
|
* Returns / as a default or when unsafe.
|
||||||
|
* @param url The URL to sanitize
|
||||||
|
*/
|
||||||
|
export const sanitizeRedirectionUrl = (url?: string) => {
|
||||||
|
if (url && url.startsWith("/") && !url.startsWith("//")) {
|
||||||
|
return url;
|
||||||
|
} else {
|
||||||
|
return '/'; // Safe default
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in new issue
Block a user