Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions client/src/components/AuthGate.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
api,
assertSafeWebAuthTransport,
getStoredToken,
isElectronCloudHttpAuthAllowed,
isInsecureRemoteHttpLocation,
setStoredToken,
} from "@/lib/api.ts";
Expand All @@ -26,7 +27,7 @@ export function AuthGate({ children }: { children: ReactNode }) {
const refresh = useCallback(async () => {
setError(null);
setState((current) => ({ status: "loading", providerWarnings: current.providerWarnings }));
if (getStoredToken() && isInsecureRemoteHttpLocation()) {
if (getStoredToken() && isInsecureRemoteHttpLocation() && !isElectronCloudHttpAuthAllowed()) {
setError(t("auth.insecure_http"));
setState({ status: "token", providerWarnings: [] });
return;
Expand Down Expand Up @@ -63,7 +64,7 @@ export function AuthGate({ children }: { children: ReactNode }) {
setSubmitting(true);
setError(null);
try {
if (isInsecureRemoteHttpLocation()) {
if (isInsecureRemoteHttpLocation() && !isElectronCloudHttpAuthAllowed()) {
setError(t("auth.insecure_http"));
return;
}
Expand Down
1 change: 1 addition & 0 deletions client/src/hooks/use-import-stream.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ export function useImportStream() {
}

fetch(`${API_BASE}/api/import/scan/stream`, {
method: 'POST',
headers,
})
.then(async (res) => {
Expand Down
7 changes: 7 additions & 0 deletions client/src/lib/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,15 @@ export function isInsecureRemoteHttpLocation(location = window.location): boolea
return location.protocol === "http:" && !LOCAL_HOSTS.has(location.hostname);
}

export function isElectronCloudHttpAuthAllowed(location = window.location): boolean {
const marker = window.chatcrystalElectronCloud;
if (!marker?.allowInsecureHttpAuth) return false;
return marker.origin === location.origin;
}

export function assertSafeWebAuthTransport(): void {
if (!isInsecureRemoteHttpLocation()) return;
if (isElectronCloudHttpAuthAllowed()) return;
throw new Error(
"Refusing to send ChatCrystal access tokens over public HTTP. Use HTTPS or a local tunnel.",
);
Expand Down
10 changes: 10 additions & 0 deletions client/src/types/electron.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
export {};

declare global {
interface Window {
chatcrystalElectronCloud?: {
allowInsecureHttpAuth: boolean;
origin: string;
};
}
}
Loading
Loading