mirror of
https://github.com/steveiliop56/tinyauth.git
synced 2026-06-23 11:50:13 +00:00
chore: copilot nits
This commit is contained in:
@@ -3,6 +3,7 @@ import { Outlet } from "react-router";
|
|||||||
import { useCallback, useEffect, useState } from "react";
|
import { useCallback, useEffect, useState } from "react";
|
||||||
import { DomainWarning } from "../domain-warning/domain-warning";
|
import { DomainWarning } from "../domain-warning/domain-warning";
|
||||||
import { QuickActions } from "../quick-actions/quick-actions";
|
import { QuickActions } from "../quick-actions/quick-actions";
|
||||||
|
import { isTrustedDomain } from "@/lib/hooks/redirect-uri";
|
||||||
|
|
||||||
const BaseLayout = ({ children }: { children: React.ReactNode }) => {
|
const BaseLayout = ({ children }: { children: React.ReactNode }) => {
|
||||||
const { ui } = useAppContext();
|
const { ui } = useAppContext();
|
||||||
@@ -40,7 +41,18 @@ export const Layout = () => {
|
|||||||
setIgnoreDomainWarning(true);
|
setIgnoreDomainWarning(true);
|
||||||
}, [setIgnoreDomainWarning]);
|
}, [setIgnoreDomainWarning]);
|
||||||
|
|
||||||
if (!ignoreDomainWarning && ui.warningsEnabled && currentUrl !== app.appUrl) {
|
const isTrusted = (() => {
|
||||||
|
try {
|
||||||
|
const appUrlObj = new URL(app.appUrl);
|
||||||
|
const currentUrlObj = new URL(currentUrl);
|
||||||
|
|
||||||
|
return isTrustedDomain(currentUrlObj, appUrlObj, "", false);
|
||||||
|
} catch {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
})();
|
||||||
|
|
||||||
|
if (!ignoreDomainWarning && ui.warningsEnabled && !isTrusted) {
|
||||||
return (
|
return (
|
||||||
<BaseLayout>
|
<BaseLayout>
|
||||||
<DomainWarning
|
<DomainWarning
|
||||||
|
|||||||
@@ -88,7 +88,7 @@ const getEffectivePort = (url: URL): string => {
|
|||||||
return "80";
|
return "80";
|
||||||
};
|
};
|
||||||
|
|
||||||
const isTrustedDomain = (
|
export const isTrustedDomain = (
|
||||||
url: URL,
|
url: URL,
|
||||||
appUrl: URL,
|
appUrl: URL,
|
||||||
cookieDomain: string,
|
cookieDomain: string,
|
||||||
|
|||||||
@@ -9,7 +9,9 @@ import (
|
|||||||
"github.com/weppos/publicsuffix-go/publicsuffix"
|
"github.com/weppos/publicsuffix-go/publicsuffix"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Get cookie domain parses a hostname and returns the upper domain (e.g. sub1.sub2.domain.com -> sub2.domain.com)
|
// GetCookieDomain parses the app url and returns the domain value to use for cookies.
|
||||||
|
// When auth for subdomains is enabled, it strips the leftmost label
|
||||||
|
// (e.g. sub1.sub2.domain.com -> sub2.domain.com), otherwise it returns the full hostname.
|
||||||
func GetCookieDomain(appUrl string, subdomainsEnabled bool) (string, error) {
|
func GetCookieDomain(appUrl string, subdomainsEnabled bool) (string, error) {
|
||||||
u, err := url.Parse(appUrl)
|
u, err := url.Parse(appUrl)
|
||||||
|
|
||||||
|
|||||||
@@ -54,7 +54,7 @@ func TestGetRootDomain(t *testing.T) {
|
|||||||
// Domain managed by ICANN
|
// Domain managed by ICANN
|
||||||
domain = "http://example.co.uk"
|
domain = "http://example.co.uk"
|
||||||
_, err = utils.GetCookieDomain(domain, true)
|
_, err = utils.GetCookieDomain(domain, true)
|
||||||
assert.Error(t, err, "domain in public suffix list, cannot set cookies")
|
assert.ErrorContains(t, err, "domain in public suffix list, cannot set cookies")
|
||||||
|
|
||||||
// Domain without subdomain
|
// Domain without subdomain
|
||||||
domain = "http://tinyauth.app"
|
domain = "http://tinyauth.app"
|
||||||
|
|||||||
Reference in New Issue
Block a user