mirror of
https://github.com/trafficlunar/tomodachi-share.git
synced 2026-05-13 13:17:45 +00:00
fix: prevent people from going to login and submit without sufficient session
also fix build errors for the 1000th time
This commit is contained in:
parent
3e87d263da
commit
9795849830
3 changed files with 17 additions and 12 deletions
|
|
@ -1,13 +1,11 @@
|
|||
import { Icon } from "@iconify/react";
|
||||
import { useStore } from "@nanostores/react";
|
||||
import { Link, useNavigate } from "react-router";
|
||||
import { Link, Navigate } from "react-router";
|
||||
import { session } from "../session";
|
||||
|
||||
export default function LoginPage() {
|
||||
const navigate = useNavigate();
|
||||
const $session = useStore(session);
|
||||
|
||||
if ($session) navigate("/");
|
||||
if ($session) return <Navigate to="/" replace />;
|
||||
|
||||
const API_URL = import.meta.env.VITE_API_URL;
|
||||
|
||||
|
|
|
|||
|
|
@ -6,20 +6,29 @@ export default function LinkOutPage() {
|
|||
const [searchParams] = useSearchParams();
|
||||
const url = searchParams.get("url");
|
||||
|
||||
if (!url || Array.isArray(url)) navigate("/");
|
||||
if (!url) {
|
||||
navigate("/");
|
||||
return null;
|
||||
}
|
||||
|
||||
let parsed: URL;
|
||||
try {
|
||||
parsed = new URL(url);
|
||||
} catch {
|
||||
navigate("/"); // redirect if URL is invalid
|
||||
return null;
|
||||
}
|
||||
|
||||
// Next.js doesn't allow attacks like these but you can never be too safe
|
||||
if (!["http:", "https:"].includes(parsed.protocol)) navigate("/");
|
||||
if (!["http:", "https:"].includes(parsed.protocol)) {
|
||||
navigate("/");
|
||||
return null;
|
||||
}
|
||||
|
||||
const isSafe = Array.from(SAFE_LINKS).some((domain) => parsed.hostname === domain || parsed.hostname.endsWith(`.${domain}`));
|
||||
if (isSafe) navigate(url);
|
||||
if (isSafe) {
|
||||
navigate(url);
|
||||
return null;
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="grow flex items-center justify-center">
|
||||
|
|
|
|||
|
|
@ -1,12 +1,10 @@
|
|||
import { useStore } from "@nanostores/react";
|
||||
import SubmitForm from "../components/submit-form";
|
||||
import { session } from "../session";
|
||||
import { useNavigate } from "react-router";
|
||||
import { Navigate } from "react-router";
|
||||
|
||||
export default function SubmitPage() {
|
||||
const navigate = useNavigate();
|
||||
const $session = useStore(session);
|
||||
|
||||
if (!$session) navigate("/login");
|
||||
if (!$session) return <Navigate to="/login" replace />;
|
||||
return <SubmitForm />;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue