7.4 billion tokens per month. 34 free LLM providers. 635 free model endpoints. All behind one /v1 endpoint, plus any custom OpenAI-compatible endpoint. Smart routing, automatic failover, encrypted keys. Personal experimentation only.
TypeScript
fix(headers,clipboard): serve the dashboard cleanly over plain HTTP (#734) (#735)
Tashfeen72658ad759da
diff --git a/client/src/components/command-palette.tsx b/client/src/components/command-palette.tsxindex 6d3e9290..f14dab4d 100644--- a/client/src/components/command-palette.tsx+++ b/client/src/components/command-palette.tsx@@ -18,6 +18,7 @@ import {Zap,} from 'lucide-react'import { apiFetch } from '@/lib/api'+import { copyText } from '@/lib/clipboard'import { toast } from '@/lib/toast'import { apiBaseUrl } from '@/components/api-usage'import { COMMAND_PALETTE_EVENT } from '@/components/command-palette-state'@@ -34,6 +35,14 @@ interface Command {run: () => void}+// Copy and report what actually happened: on an insecure origin (a plain-HTTP+// LAN install) the copy can fail, and a success toast over an empty clipboard+// is worse than no toast at all (#734).+async function copyAndToast(value: string, success: string, failure: string) {+ if (await copyText(value)) toast.success(success)+ else toast.error(failure)+}+// Cmd+K / Ctrl+K palette: jump to any page or model, toggle theme, copy the// unified key or base URL. Zero-dep overlay; list is keyboard-driven// (arrows + Enter) with proper listbox semantics.@@ -126,8 +135,7 @@ export function CommandPalette() {icon: Copy,run: () => {if (!keyData?.apiKey) return- void navigator.clipboard?.writeText(keyData.apiKey)- toast.success(t('setup.copiedKey'))+ void copyAndToast(keyData.apiKey, t('setup.copiedKey'), t('common.copyFailed'))},},{@@ -137,8 +145,7 @@ export function CommandPalette() {keywords: 'copy base url endpoint',icon: Copy,run: () => {- void navigator.clipboard?.writeText(apiBaseUrl())- toast.success(t('setup.copiedUrl'))+ void copyAndToast(apiBaseUrl(), t('setup.copiedUrl'), t('common.copyFailed'))},},]diff --git a/client/src/components/copy-button.tsx b/client/src/components/copy-button.tsxindex 49be60fd..88aff29e 100644--- a/client/src/components/copy-button.tsx+++ b/client/src/components/copy-button.tsx@@ -1,6 +1,9 @@import { useState } from 'react'import { Copy, Check } from 'lucide-react'import { cn } from '@/lib/utils'+import { copyText } from '@/lib/clipboard'+import { toast } from '@/lib/toast'+import { useI18n } from '@/i18n'interface CopyButtonProps {text: string@@ -11,15 +14,24 @@ interface CopyButtonProps {// Small icon button that copies `text` to the clipboard and briefly shows a// check. Shared by markdown code blocks and Playground replies.export function CopyButton({ text, className, label = 'Copy' }: CopyButtonProps) {+ const { t } = useI18n()const [copied, setCopied] = useState(false)return (<buttontype="button"aria-label={copied ? 'Copied' : label}onClick={() => {- void navigator.clipboard?.writeText(text)- setCopied(true)- setTimeout(() => setCopied(false), 1500)+ // Only claim success once the text is really on the clipboard: on an+ // insecure origin the copy can fail, and a check mark over an empty+ // clipboard is worse than no feedback at all (#734).+ void copyText(text).then(ok => {+ if (!ok) {+ toast.error(t('common.copyFailed'))+ return+ }+ setCopied(true)+ setTimeout(() => setCopied(false), 1500)+ })}}className={cn('inline-flex items-center justify-center rounded-md border bg-background/80 text-muted-foreground transition-colors hover:text-foreground',diff --git a/client/src/components/getting-started.tsx b/client/src/components/getting-started.tsxindex 3ed85284..27a6417e 100644--- a/client/src/components/getting-started.tsx+++ b/client/src/components/getting-started.tsx@@ -3,6 +3,7 @@ import { Link } from 'react-router-dom'import { useQuery } from '@tanstack/react-query'import { ArrowRight, Check, Copy, X } from 'lucide-react'import { apiFetch } from '@/lib/api'+import { copyText } from '@/lib/clipboard'import { toast } from '@/lib/toast'import { apiBaseUrl } from '@/components/api-usage'import { Button } from '@/components/ui/button'@@ -53,10 +54,15 @@ export function GettingStarted() {const doneCount = [hasKeys, hasRequest, connected].filter(Boolean).lengthfunction copyValue(value: string, message: string) {- void navigator.clipboard?.writeText(value)- toast.success(message)- setConnected(true)- writeFlag(CONNECT_KEY)+ void copyText(value).then(ok => {+ if (!ok) {+ toast.error(t('common.copyFailed'))+ return+ }+ toast.success(message)+ setConnected(true)+ writeFlag(CONNECT_KEY)+ })}return (diff --git a/client/src/components/keys/copy-key-dialog.tsx b/client/src/components/keys/copy-key-dialog.tsxindex 03b46b39..41f89b42 100644--- a/client/src/components/keys/copy-key-dialog.tsx+++ b/client/src/components/keys/copy-key-dialog.tsx@@ -6,6 +6,7 @@ import { Input } from '@/components/ui/input'import { Label } from '@/components/ui/label'import { FieldError } from '@/components/ui/field-error'import { apiFetch } from '@/lib/api'+import { copyText } from '@/lib/clipboard'import { useI18n } from '@/i18n'import { toast } from '@/lib/toast'@@ -29,6 +30,9 @@ export function CopyKeyDialog({const [password, setPassword] = useState('')const [error, setError] = useState<string | null>(null)const [busy, setBusy] = useState(false)+ // Only set when the clipboard refused: the key is on screen for a manual+ // copy, and disappears again with the dialog.+ const [revealed, setRevealed] = useState<string | null>(null)async function submit(e: FormEvent) {e.preventDefault()@@ -39,12 +43,20 @@ export function CopyKeyDialog({method: 'POST',headers: { 'x-reauth-password': password },})- await navigator.clipboard.writeText(key)+ // A plain-HTTP LAN origin has no Clipboard API at all, so this falls back+ // to execCommand rather than throwing (#734). If even that fails the key+ // has already been revealed — show it instead of discarding it, or the+ // password round trip was for nothing.+ if (!await copyText(key)) {+ setRevealed(key)+ setError(t('common.copyFailed'))+ return+ }toast.success(t('keys.copiedKey'))onOpenChange(false)} catch (err) {- // Wrong password and a clipboard the browser refused both land here, and- // both are things to fix in place rather than behind a closed dialog.+ // A wrong password lands here; it is worth fixing in place rather than+ // behind a closed dialog.setError((err as Error).message)setPassword('')} finally {@@ -56,7 +68,11 @@ export function CopyKeyDialog({<Dialog open onOpenChange={onOpenChange}><DialogPopup maxWidth="max-w-md"><DialogTitle>{t('keys.copyFullKey')}</DialogTitle>- <code className="mt-2 block font-mono text-[11px] text-muted-foreground">{maskedKey}</code>+ {/* select-all + break-all so the fallback key can be grabbed in one+ click and still fits the dialog. */}+ <code className="mt-2 block font-mono text-[11px] text-muted-foreground break-all select-all">+ {revealed ?? maskedKey}+ </code><form onSubmit={submit} className="mt-4 space-y-4"><div className="space-y-1.5">diff --git a/client/src/components/keys/unified-key-section.tsx b/client/src/components/keys/unified-key-section.tsxindex cba92a13..de87e357 100644--- a/client/src/components/keys/unified-key-section.tsx+++ b/client/src/components/keys/unified-key-section.tsx@@ -1,6 +1,8 @@import { useState } from 'react'import { useQuery, useMutation, useQueryClient } from '@tanstack/react-query'import { apiFetch } from '@/lib/api'+import { copyText } from '@/lib/clipboard'+import { toast } from '@/lib/toast'import { Button } from '@/components/ui/button'import { useI18n } from '@/i18n'@@ -26,8 +28,11 @@ export function UnifiedKeySection() {? `http://${window.location.hostname}:${__SERVER_PORT__}/v1`: `${window.location.origin}/v1`- function copy() {- navigator.clipboard.writeText(apiKey)+ async function copy() {+ if (!await copyText(apiKey)) {+ toast.error(t('common.copyFailed'))+ return+ }setCopied(true)setTimeout(() => setCopied(false), 1500)}@@ -63,7 +68,7 @@ export function UnifiedKeySection() {<Button variant="outline" size="sm" onClick={() => setShowKey(!showKey)}>{showKey ? t('keys.hideKey') : t('keys.showKey')}</Button>- <Button variant="outline" size="sm" onClick={copy}>+ <Button variant="outline" size="sm" onClick={() => void copy()}>{copied ? t('keys.copiedKey') : t('keys.copyKey')}</Button></div>diff --git a/client/src/i18n/locales/am.json b/client/src/i18n/locales/am.jsonindex e333962d..abc3f3eb 100644--- a/client/src/i18n/locales/am.json+++ b/client/src/i18n/locales/am.json@@ -67,6 +67,7 @@"confirm": "አረጋግጥ","copy": "ቅዳ","copied": "ተቀድዟል",+ "copyFailed": "መቅዳት አልተቻለም — ጽሑፉን መርጠው በእጅ ይቅዱ","show": "አሳይ","hide": "መደበቅ","apply": "ተግብር",diff --git a/client/src/i18n/locales/ar.json b/client/src/i18n/locales/ar.jsonindex 2ef5913a..d13ae433 100644--- a/client/src/i18n/locales/ar.json+++ b/client/src/i18n/locales/ar.json@@ -67,6 +67,7 @@"confirm": "تأكيد","copy": "نسخ","copied": "منقول",+ "copyFailed": "تعذّر النسخ — حدّد النص وانسخه يدويًا","show": "عرض","hide": "إخفاء","apply": "تطبيق",diff --git a/client/src/i18n/locales/az.json b/client/src/i18n/locales/az.jsonindex 65415e2f..fac2de7f 100644--- a/client/src/i18n/locales/az.json+++ b/client/src/i18n/locales/az.json@@ -67,6 +67,7 @@"confirm": "Təsdiqlə","copy": "Alındı","copied": "Kopyalandı",+ "copyFailed": "Kopyalamaq alınmadı — mətni seçib əl ilə kopyalayın","show": "Şou","hide": "Gizlən","apply": "Müraciət et",diff --git a/client/src/i18n/locales/bg.json b/client/src/i18n/locales/bg.jsonindex c7e65537..89d0ce55 100644--- a/client/src/i18n/locales/bg.json+++ b/client/src/i18n/locales/bg.json@@ -67,6 +67,7 @@"confirm": "Потвърдете","copy": "Прието.","copied": "Копирано",+ "copyFailed": "Копирането не бе успешно — маркирайте текста и го копирайте ръчно","show": "Шоу","hide": "Скрий се","apply": "Кандидатствайте",diff --git a/client/src/i18n/locales/bn.json b/client/src/i18n/locales/bn.jsonindex 3c48230a..6298aabc 100644--- a/client/src/i18n/locales/bn.json+++ b/client/src/i18n/locales/bn.json@@ -67,6 +67,7 @@"confirm": "নিশ্চিত করুন","copy": "কপি","copied": "কপি করা হয়েছে",+ "copyFailed": "কপি করা যায়নি — টেক্সট নির্বাচন করে নিজে কপি করুন","show": "দেখান","hide": "লুকান","apply": "আবেদন করুন",diff --git a/client/src/i18n/locales/cs.json b/client/src/i18n/locales/cs.jsonindex 8ce39d92..41cb64e7 100644--- a/client/src/i18n/locales/cs.json+++ b/client/src/i18n/locales/cs.json@@ -67,6 +67,7 @@"confirm": "Potvrďte","copy": "Rozumím","copied": "Zkopírováno",+ "copyFailed": "Nepodařilo se zkopírovat — označte text a zkopírujte ho ručně","show": "Pořad","hide": "Schovej se","apply": "Přihlaste se",diff --git a/client/src/i18n/locales/da.json b/client/src/i18n/locales/da.jsonindex d79daa78..b6e1c651 100644--- a/client/src/i18n/locales/da.json+++ b/client/src/i18n/locales/da.json@@ -67,6 +67,7 @@"confirm": "Bekræft","copy": "Modtaget","copied": "Kopieret",+ "copyFailed": "Kunne ikke kopiere — markér teksten, og kopiér manuelt","show": "Show","hide": "Gem dig","apply": "Ansøg",diff --git a/client/src/i18n/locales/de.json b/client/src/i18n/locales/de.jsonindex 11952449..06442c48 100644--- a/client/src/i18n/locales/de.json+++ b/client/src/i18n/locales/de.json@@ -67,6 +67,7 @@"confirm": "Bestätigen","copy": "Kopieren","copied": "Kopiert",+ "copyFailed": "Kopieren fehlgeschlagen — Text markieren und manuell kopieren","show": "Zeigen","hide": "Verstecken","apply": "Bewerben",diff --git a/client/src/i18n/locales/el.json b/client/src/i18n/locales/el.jsonindex 6bb52e88..ba49fa65 100644--- a/client/src/i18n/locales/el.json+++ b/client/src/i18n/locales/el.json@@ -67,6 +67,7 @@"confirm": "Επιβεβαιώνω","copy": "Αντιγραφή","copied": "Αντιγράφηκε",+ "copyFailed": "Δεν ήταν δυνατή η αντιγραφή — επιλέξτε το κείμενο και αντιγράψτε το χειροκίνητα","show": "Προβολή","hide": "Απόκρυψη","apply": "Εφαρμογή",diff --git a/client/src/i18n/locales/en.json b/client/src/i18n/locales/en.jsonindex 6cc3e1e1..6eb34d76 100644--- a/client/src/i18n/locales/en.json+++ b/client/src/i18n/locales/en.json@@ -67,6 +67,7 @@"confirm": "Confirm","copy": "Copy","copied": "Copied",+ "copyFailed": "Couldn't copy — select the text and copy it manually","show": "Show","hide": "Hide","apply": "Apply",diff --git a/client/src/i18n/locales/es.json b/client/src/i18n/locales/es.jsonindex 6351cc42..b2f711e3 100644--- a/client/src/i18n/locales/es.json+++ b/client/src/i18n/locales/es.json@@ -67,6 +67,7 @@"confirm": "Confirmar","copy": "Copiar","copied": "Copiado",+ "copyFailed": "No se pudo copiar — selecciona el texto y cópialo manualmente","show": "Mostrar","hide": "Ocultar","apply": "Aplicar",diff --git a/client/src/i18n/locales/fa.json b/client/src/i18n/locales/fa.jsonindex bfbff1c7..04f022cb 100644--- a/client/src/i18n/locales/fa.json+++ b/client/src/i18n/locales/fa.json@@ -67,6 +67,7 @@"confirm": "تایید کنید","copy": "کپی کنید","copied": "کپی شده است",+ "copyFailed": "کپی نشد — متن را انتخاب و دستی کپی کنید","show": "نمایش دهید","hide": "پنهان کردن","apply": "درخواست کنید",diff --git a/client/src/i18n/locales/fi.json b/client/src/i18n/locales/fi.jsonindex 92d451a3..019a1b93 100644--- a/client/src/i18n/locales/fi.json+++ b/client/src/i18n/locales/fi.json@@ -67,6 +67,7 @@"confirm": "Vahvista","copy": "Selvä","copied": "Kopioitu",+ "copyFailed": "Kopiointi epäonnistui — valitse teksti ja kopioi käsin","show": "Ohjelma","hide": "Piiloudu","apply": "Hae",diff --git a/client/src/i18n/locales/fr.json b/client/src/i18n/locales/fr.jsonindex 07260d80..2fbd10dd 100644--- a/client/src/i18n/locales/fr.json+++ b/client/src/i18n/locales/fr.json@@ -67,6 +67,7 @@"confirm": "Confirmer","copy": "Copier","copied": "Copié",+ "copyFailed": "Copie impossible — sélectionnez le texte et copiez-le manuellement","show": "Afficher","hide": "Masquer","apply": "Appliquer",diff --git a/client/src/i18n/locales/gu.json b/client/src/i18n/locales/gu.jsonindex 8f7d0518..16521682 100644--- a/client/src/i18n/locales/gu.json+++ b/client/src/i18n/locales/gu.json@@ -67,6 +67,7 @@"confirm": "પુષ્ટિ કરો","copy": "નકલ કરો","copied": "નકલ કરી",+ "copyFailed": "કૉપિ થઈ શક્યું નહીં — ટેક્સ્ટ પસંદ કરીને જાતે કૉપિ કરો","show": "બતાવો","hide": "છુપાવો","apply": "અરજી કરો",diff --git a/client/src/i18n/locales/ha.json b/client/src/i18n/locales/ha.jsonindex 4ff42131..41f583f4 100644--- a/client/src/i18n/locales/ha.json+++ b/client/src/i18n/locales/ha.json@@ -67,6 +67,7 @@"confirm": "Tabbatar","copy": "Kwafi","copied": "Kwafi",+ "copyFailed": "An kasa kwafi — zaɓi rubutun ka kwafa da hannu","show": "Nuna","hide": "Boye","apply": "Aiwatar",diff --git a/client/src/i18n/locales/he.json b/client/src/i18n/locales/he.jsonindex ec0d0b87..0ab63115 100644--- a/client/src/i18n/locales/he.json+++ b/client/src/i18n/locales/he.json@@ -67,6 +67,7 @@"confirm": "אישור","copy": "העתק","copied": "הועתק",+ "copyFailed": "ההעתקה נכשלה — סמנו את הטקסט והעתיקו ידנית","show": "תוכנית","hide": "הסתתר","apply": "הגיש מועמדות",diff --git a/client/src/i18n/locales/hi.json b/client/src/i18n/locales/hi.jsonindex ae83d04b..bb2937ed 100644--- a/client/src/i18n/locales/hi.json+++ b/client/src/i18n/locales/hi.json@@ -67,6 +67,7 @@"confirm": "पुष्टि करें","copy": "प्रतिलिपि","copied": "नकल की गई",+ "copyFailed": "कॉपी नहीं हो सका — टेक्स्ट चुनकर मैन्युअल रूप से कॉपी करें","show": "दिखाओ","hide": "छिपाओ","apply": "आवेदन करें",diff --git a/client/src/i18n/locales/hr.json b/client/src/i18n/locales/hr.jsonindex ad54827b..27d0f1c6 100644--- a/client/src/i18n/locales/hr.json+++ b/client/src/i18n/locales/hr.json@@ -67,6 +67,7 @@"confirm": "Potvrdi","copy": "Primljeno","copied": "Kopirano",+ "copyFailed": "Kopiranje nije uspjelo — označite tekst i kopirajte ga ručno","show": "Emisija","hide": "Sakrij se","apply": "Prijavite se",diff --git a/client/src/i18n/locales/hu.json b/client/src/i18n/locales/hu.jsonindex 38a4fd61..a81cdc82 100644--- a/client/src/i18n/locales/hu.json+++ b/client/src/i18n/locales/hu.json@@ -67,6 +67,7 @@"confirm": "Megerősítse","copy": "Értettem","copied": "Másolva",+ "copyFailed": "Nem sikerült a másolás — jelölje ki a szöveget, és másolja kézzel","show": "Műsor","hide": "Bújj el","apply": "Jelentkezz",diff --git a/client/src/i18n/locales/id.json b/client/src/i18n/locales/id.jsonindex 1fce7cd5..e0f2212a 100644--- a/client/src/i18n/locales/id.json+++ b/client/src/i18n/locales/id.json@@ -67,6 +67,7 @@"confirm": "Konfirmasikan","copy": "Salin","copied": "Disalin",+ "copyFailed": "Gagal menyalin — pilih teksnya dan salin secara manual","show": "Tunjukkan","hide": "Sembunyikan","apply": "Terapkan",diff --git a/client/src/i18n/locales/ig.json b/client/src/i18n/locales/ig.jsonindex 39b76529..cded40fb 100644--- a/client/src/i18n/locales/ig.json+++ b/client/src/i18n/locales/ig.json@@ -67,6 +67,7 @@"confirm": "Kwenye","copy": "Detuo","copied": "Eṅomiri",+ "copyFailed": "Enweghị ike ịdepụta — họrọ ederede ahụ wee depụta ya n'aka","show": "Gosi","hide": "Zoo","apply": "Tinye",diff --git a/client/src/i18n/locales/it.json b/client/src/i18n/locales/it.jsonindex 69184731..93487c22 100644--- a/client/src/i18n/locales/it.json+++ b/client/src/i18n/locales/it.json@@ -67,6 +67,7 @@"confirm": "Conferma","copy": "Copia","copied": "Copiato",+ "copyFailed": "Copia non riuscita — seleziona il testo e copialo manualmente","show": "Mostra","hide": "Nascondi","apply": "Applica",diff --git a/client/src/i18n/locales/ja.json b/client/src/i18n/locales/ja.jsonindex c2a9e4ce..77d5a76f 100644--- a/client/src/i18n/locales/ja.json+++ b/client/src/i18n/locales/ja.json@@ -67,6 +67,7 @@"confirm": "確認する","copy": "コピー","copied": "コピーされました",+ "copyFailed": "コピーできませんでした — テキストを選択して手動でコピーしてください","show": "表示する","hide": "隠す","apply": "申し込む",diff --git a/client/src/i18n/locales/ka.json b/client/src/i18n/locales/ka.jsonindex d8a63332..a8fc095a 100644--- a/client/src/i18n/locales/ka.json+++ b/client/src/i18n/locales/ka.json@@ -67,6 +67,7 @@"confirm": "დაადასტურეთ","copy": "კოპირება","copied": "კოპირებულია",+ "copyFailed": "კოპირება ვერ მოხერხდა — მონიშნეთ ტექსტი და ხელით დააკოპირეთ","show": "ჩვენება","hide": "დამალვა","apply": "მიმართეთ",diff --git a/client/src/i18n/locales/km.json b/client/src/i18n/locales/km.jsonindex 67301a4c..055a33f9 100644--- a/client/src/i18n/locales/km.json+++ b/client/src/i18n/locales/km.json@@ -67,6 +67,7 @@"confirm": "បញ្ជាក់","copy": "ចម្លង","copied": "បានចម្លង",+ "copyFailed": "មិនអាចចម្លងបានទេ — សូមជ្រើសរើសអត្ថបទ ហើយចម្លងដោយដៃ","show": "ការបង្ហាញ","hide": "លាក់ខ្លួន","apply": "ដាក់ពាក្យ",diff --git a/client/src/i18n/locales/kn.json b/client/src/i18n/locales/kn.jsonindex 0075a7a3..4a61b952 100644--- a/client/src/i18n/locales/kn.json+++ b/client/src/i18n/locales/kn.json@@ -67,6 +67,7 @@"confirm": "ದೃಢೀಕರಿಸಿ","copy": "ನಕಲು ಮಾಡಿ","copied": "ನಕಲು ಮಾಡಲಾಗಿದೆ",+ "copyFailed": "ನಕಲಿಸಲು ಸಾಧ್ಯವಾಗಲಿಲ್ಲ — ಪಠ್ಯವನ್ನು ಆಯ್ಕೆಮಾಡಿ ಸ್ವತಃ ನಕಲಿಸಿ","show": "ತೋರಿಸು","hide": "ಮರೆಮಾಡಿ","apply": "ಅನ್ವಯಿಸು",diff --git a/client/src/i18n/locales/ko.json b/client/src/i18n/locales/ko.jsonindex adce0768..5c9f27c7 100644--- a/client/src/i18n/locales/ko.json+++ b/client/src/i18n/locales/ko.json@@ -67,6 +67,7 @@"confirm": "확인","copy": "복사","copied": "복사됨",+ "copyFailed": "복사하지 못했습니다 — 텍스트를 선택해 직접 복사하세요","show": "쇼","hide": "숨기기","apply": "적용",diff --git a/client/src/i18n/locales/lt.json b/client/src/i18n/locales/lt.jsonindex 3dedb6ea..43a79f9d 100644--- a/client/src/i18n/locales/lt.json+++ b/client/src/i18n/locales/lt.json@@ -67,6 +67,7 @@"confirm": "Patvirtinkite","copy": "Supratau","copied": "Nukopijuota",+ "copyFailed": "Nepavyko nukopijuoti — pažymėkite tekstą ir nukopijuokite rankiniu būdu","show": "Laida","hide": "Slėpkis","apply": "Pateikite paraišką",diff --git a/client/src/i18n/locales/ml.json b/client/src/i18n/locales/ml.jsonindex 603ee0b4..52f29e42 100644--- a/client/src/i18n/locales/ml.json+++ b/client/src/i18n/locales/ml.json@@ -67,6 +67,7 @@"confirm": "സ്ഥിരീകരിക്കുക","copy": "പകർത്തുക","copied": "പകർത്തി",+ "copyFailed": "പകർത്താനായില്ല — ടെക്സ്റ്റ് തിരഞ്ഞെടുത്ത് സ്വയം പകർത്തുക","show": "കാണിക്കുക","hide": "മറയ്ക്കുക","apply": "അപേക്ഷിക്കുക",diff --git a/client/src/i18n/locales/mr.json b/client/src/i18n/locales/mr.jsonindex 299a0e50..2a07c351 100644--- a/client/src/i18n/locales/mr.json+++ b/client/src/i18n/locales/mr.json@@ -67,6 +67,7 @@"confirm": "पुष्टी करा","copy": "कॉपी करा","copied": "कॉपी केले",+ "copyFailed": "कॉपी करता आले नाही — मजकूर निवडून स्वतः कॉपी करा","show": "दाखवा","hide": "लपवा","apply": "अर्ज करा",diff --git a/client/src/i18n/locales/ms.json b/client/src/i18n/locales/ms.jsonindex 011a93b9..00414ddd 100644--- a/client/src/i18n/locales/ms.json+++ b/client/src/i18n/locales/ms.json@@ -67,6 +67,7 @@"confirm": "Sahkan","copy": "Salin","copied": "disalin",+ "copyFailed": "Gagal menyalin — pilih teks dan salin secara manual","show": "Tunjuk","hide": "sembunyikan","apply": "Mohon",diff --git a/client/src/i18n/locales/my.json b/client/src/i18n/locales/my.jsonindex 97465f22..99f71391 100644--- a/client/src/i18n/locales/my.json+++ b/client/src/i18n/locales/my.json@@ -67,6 +67,7 @@"confirm": "အတည်ပြုပါ","copy": "မိတ္တူယူပါ","copied": "မိတ္တူယူပြီး",+ "copyFailed": "မကူးယူနိုင်ပါ — စာသားကို ရွေးပြီး ကိုယ်တိုင်ကူးယူပါ","show": "ပြသမှု","hide": "ဖုံးကွယ်ပါ","apply": "လျှောက်ထားပါ",diff --git a/client/src/i18n/locales/ne.json b/client/src/i18n/locales/ne.jsonindex 1de89c81..940655f1 100644--- a/client/src/i18n/locales/ne.json+++ b/client/src/i18n/locales/ne.json@@ -67,6 +67,7 @@"confirm": "यकिन गर्नुहोस्","copy": "प्रतिलिपि बनाउनुहोस्","copied": "प्रतिलिपि बनाइएको",+ "copyFailed": "कपी गर्न सकिएन — पाठ छानेर आफैँ कपी गर्नुहोस्","show": "देखाउनुहोस्","hide": "लुकाउनुहोस्","apply": "लागू गर्नुहोस्",diff --git a/client/src/i18n/locales/nl.json b/client/src/i18n/locales/nl.jsonindex 1b84d9fd..da6aebc3 100644--- a/client/src/i18n/locales/nl.json+++ b/client/src/i18n/locales/nl.json@@ -67,6 +67,7 @@"confirm": "Bevestig","copy": "Begrepen","copied": "Gekopieerd",+ "copyFailed": "Kopiëren mislukt — selecteer de tekst en kopieer handmatig","show": "Show","hide": "Verstop","apply": "Solliciteer",diff --git a/client/src/i18n/locales/no.json b/client/src/i18n/locales/no.jsonindex d931c495..50355c2e 100644--- a/client/src/i18n/locales/no.json+++ b/client/src/i18n/locales/no.json@@ -67,6 +67,7 @@"confirm": "Bekreft","copy": "Kopiert","copied": "Kopiert",+ "copyFailed": "Kunne ikke kopiere — merk teksten og kopier manuelt","show": "Show","hide": "Gjem deg","apply": "Søk",diff --git a/client/src/i18n/locales/or.json b/client/src/i18n/locales/or.jsonindex 6107fd13..c8a7abf9 100644--- a/client/src/i18n/locales/or.json+++ b/client/src/i18n/locales/or.json@@ -67,6 +67,7 @@"confirm": "ନିଶ୍ଚିତ କରନ୍ତୁ","copy": "କପି","copied": "କପି ହୋଇଛି",+ "copyFailed": "କପି କରାଯାଇପାରିଲା ନାହିଁ — ଟେକ୍ସଟ୍ ବାଛି ନିଜେ କପି କରନ୍ତୁ","show": "ଦେଖାନ୍ତୁ","hide": "ଲୁଚାନ୍ତୁ","apply": "ଆବେଦନ କରନ୍ତୁ",diff --git a/client/src/i18n/locales/pa.json b/client/src/i18n/locales/pa.jsonindex 8e16a4fe..8980ec6e 100644--- a/client/src/i18n/locales/pa.json+++ b/client/src/i18n/locales/pa.json@@ -67,6 +67,7 @@"confirm": "ਪੁਸ਼ਟੀ ਕਰੋ","copy": "ਕਾਪੀ ਕਰੋ","copied": "ਕਾਪੀ ਕੀਤਾ",+ "copyFailed": "ਕਾਪੀ ਨਹੀਂ ਹੋ ਸਕਿਆ — ਟੈਕਸਟ ਚੁਣ ਕੇ ਖੁਦ ਕਾਪੀ ਕਰੋ","show": "ਦਿਖਾਓ","hide": "ਓਹਲੇ","apply": "ਲਾਗੂ ਕਰੋ",diff --git a/client/src/i18n/locales/pl.json b/client/src/i18n/locales/pl.jsonindex 04667a3a..cd8a34fe 100644--- a/client/src/i18n/locales/pl.json+++ b/client/src/i18n/locales/pl.json@@ -67,6 +67,7 @@"confirm": "Potwierdź","copy": "Kopiuj","copied": "Skopiowano",+ "copyFailed": "Nie udało się skopiować — zaznacz tekst i skopiuj ręcznie","show": "Pokaż","hide": "Ukryj","apply": "Zastosuj",diff --git a/client/src/i18n/locales/pt-BR.json b/client/src/i18n/locales/pt-BR.jsonindex ad7eaedb..384176de 100644--- a/client/src/i18n/locales/pt-BR.json+++ b/client/src/i18n/locales/pt-BR.json@@ -67,6 +67,7 @@"confirm": "Confirmar","copy": "Copiar","copied": "Copiado",+ "copyFailed": "Não foi possível copiar — selecione o texto e copie manualmente","show": "Mostrar","hide": "Ocultar","apply": "Aplicar",diff --git a/client/src/i18n/locales/pt-PT.json b/client/src/i18n/locales/pt-PT.jsonindex a5eeaba9..57e587a9 100644--- a/client/src/i18n/locales/pt-PT.json+++ b/client/src/i18n/locales/pt-PT.json@@ -67,6 +67,7 @@"confirm": "Confirmar","copy": "Cópia","copied": "Copiado",+ "copyFailed": "Não foi possível copiar — selecione o texto e copie manualmente","show": "Programa","hide": "Esconde-te","apply": "Candidata-te",diff --git a/client/src/i18n/locales/ro.json b/client/src/i18n/locales/ro.jsonindex c6bbe004..a399df7f 100644--- a/client/src/i18n/locales/ro.json+++ b/client/src/i18n/locales/ro.json@@ -67,6 +67,7 @@"confirm": "Confirmă","copy": "Recepționat","copied": "Copiat",+ "copyFailed": "Nu s-a putut copia — selectează textul și copiază-l manual","show": "Emisiune","hide": "Ascunde-te","apply": "Aplică",diff --git a/client/src/i18n/locales/ru.json b/client/src/i18n/locales/ru.jsonindex b0b446a9..c2f37807 100644--- a/client/src/i18n/locales/ru.json+++ b/client/src/i18n/locales/ru.json@@ -67,6 +67,7 @@"confirm": "Подтвердить","copy": "Копировать","copied": "Скопировано",+ "copyFailed": "Не удалось скопировать — выделите текст и скопируйте вручную","show": "Показать","hide": "Скрыть","apply": "Применить",diff --git a/client/src/i18n/locales/si.json b/client/src/i18n/locales/si.jsonindex 4b33dfc4..1cc60c0f 100644--- a/client/src/i18n/locales/si.json+++ b/client/src/i18n/locales/si.json@@ -67,6 +67,7 @@"confirm": "තහවුරු කරන්න","copy": "පිටපත් කරන්න","copied": "පිටපත් කර ඇත",+ "copyFailed": "පිටපත් කළ නොහැකි විය — පෙළ තෝරා අතින් පිටපත් කරන්න","show": "පෙන්වන්න","hide": "සඟවන්න","apply": "අයදුම් කරන්න",diff --git a/client/src/i18n/locales/sk.json b/client/src/i18n/locales/sk.jsonindex 00ee5609..918045f1 100644--- a/client/src/i18n/locales/sk.json+++ b/client/src/i18n/locales/sk.json@@ -67,6 +67,7 @@"confirm": "Potvrď","copy": "Rozumiem","copied": "Skopírované",+ "copyFailed": "Nepodarilo sa skopírovať — označte text a skopírujte ho ručne","show": "Relácia","hide": "Schovaj sa","apply": "Prihláste sa",diff --git a/client/src/i18n/locales/sr.json b/client/src/i18n/locales/sr.jsonindex 241e6fd5..d788a503 100644--- a/client/src/i18n/locales/sr.json+++ b/client/src/i18n/locales/sr.json@@ -67,6 +67,7 @@"confirm": "Потврди","copy": "Копирај","copied": "Копирано",+ "copyFailed": "Копирање није успело — означите текст и копирајте га ручно","show": "Схов","hide": "Сакриј се","apply": "Пријавите се",diff --git a/client/src/i18n/locales/sv.json b/client/src/i18n/locales/sv.jsonindex b1f4c3b6..81669e51 100644--- a/client/src/i18n/locales/sv.json+++ b/client/src/i18n/locales/sv.json@@ -67,6 +67,7 @@"confirm": "Bekräfta","copy": "Kopiera","copied": "Kopierat",+ "copyFailed": "Det gick inte att kopiera — markera texten och kopiera manuellt","show": "Show","hide": "Göm dig","apply": "Ansök",diff --git a/client/src/i18n/locales/sw.json b/client/src/i18n/locales/sw.jsonindex f8b68b21..2916eb60 100644--- a/client/src/i18n/locales/sw.json+++ b/client/src/i18n/locales/sw.json@@ -67,6 +67,7 @@"confirm": "Thibitisha","copy": "Nakili","copied": "Imenakiliwa",+ "copyFailed": "Imeshindwa kunakili — chagua maandishi na unakili mwenyewe","show": "Onyesha","hide": "Ficha","apply": "Omba",diff --git a/client/src/i18n/locales/ta.json b/client/src/i18n/locales/ta.jsonindex f3d8005f..538a23bd 100644--- a/client/src/i18n/locales/ta.json+++ b/client/src/i18n/locales/ta.json@@ -67,6 +67,7 @@"confirm": "உறுதிப்படுத்தவும்","copy": "நகலெடுக்கவும்","copied": "நகலெடுக்கப்பட்டது",+ "copyFailed": "நகலெடுக்க முடியவில்லை — உரையைத் தேர்ந்தெடுத்து கைமுறையாக நகலெடுக்கவும்","show": "காட்டு","hide": "மறை","apply": "விண்ணப்பிக்கவும்",diff --git a/client/src/i18n/locales/te.json b/client/src/i18n/locales/te.jsonindex 8c07bce4..8eb7e0e2 100644--- a/client/src/i18n/locales/te.json+++ b/client/src/i18n/locales/te.json@@ -67,6 +67,7 @@"confirm": "నిర్ధారించండి","copy": "కాపీ చేయండి","copied": "కాపీ చేయబడింది",+ "copyFailed": "కాపీ చేయలేకపోయాం — వచనాన్ని ఎంచుకుని మాన్యువల్గా కాపీ చేయండి","show": "చూపించు","hide": "దాచు","apply": "దరఖాస్తు చేసుకోండి",diff --git a/client/src/i18n/locales/th.json b/client/src/i18n/locales/th.jsonindex 3e912108..0062e02e 100644--- a/client/src/i18n/locales/th.json+++ b/client/src/i18n/locales/th.json@@ -67,6 +67,7 @@"confirm": "ยืนยัน","copy": "คัดลอก","copied": "คัดลอกแล้ว",+ "copyFailed": "คัดลอกไม่สำเร็จ — เลือกข้อความแล้วคัดลอกเอง","show": "แสดง","hide": "ซ่อน","apply": "สมัคร",diff --git a/client/src/i18n/locales/tl.json b/client/src/i18n/locales/tl.jsonindex 33b3f2cc..74c8bd66 100644--- a/client/src/i18n/locales/tl.json+++ b/client/src/i18n/locales/tl.json@@ -67,6 +67,7 @@"confirm": "Kumpirmahin","copy": "Kopyahin","copied": "kinopya",+ "copyFailed": "Hindi makopya — piliin ang teksto at kopyahin nang manu-mano","show": "Ipakita","hide": "itago","apply": "Mag-apply",diff --git a/client/src/i18n/locales/tr.json b/client/src/i18n/locales/tr.jsonindex fb0fbb7d..6b6c8ee7 100644--- a/client/src/i18n/locales/tr.json+++ b/client/src/i18n/locales/tr.json@@ -67,6 +67,7 @@"confirm": "Onayla","copy": "Kopyala","copied": "Kopyalandı",+ "copyFailed": "Kopyalanamadı — metni seçip elle kopyalayın","show": "Göster","hide": "Gizle","apply": "Uygula",diff --git a/client/src/i18n/locales/uk.json b/client/src/i18n/locales/uk.jsonindex 78527037..3ac7594a 100644--- a/client/src/i18n/locales/uk.json+++ b/client/src/i18n/locales/uk.json@@ -67,6 +67,7 @@"confirm": "Підтвердити","copy": "Копія","copied": "Скопійовано",+ "copyFailed": "Не вдалося скопіювати — виділіть текст і скопіюйте вручну","show": "Показати","hide": "Сховати","apply": "Застосувати",diff --git a/client/src/i18n/locales/ur.json b/client/src/i18n/locales/ur.jsonindex 18e0c15d..77e73640 100644--- a/client/src/i18n/locales/ur.json+++ b/client/src/i18n/locales/ur.json@@ -67,6 +67,7 @@"confirm": "تصدیق کریں۔","copy": "کاپی","copied": "کاپی",+ "copyFailed": "کاپی نہیں ہو سکا — متن منتخب کر کے دستی طور پر کاپی کریں","show": "دکھائیں۔","hide": "چھپائیں","apply": "لگائیں",diff --git a/client/src/i18n/locales/uz.json b/client/src/i18n/locales/uz.jsonindex 2920a461..d8de55ea 100644--- a/client/src/i18n/locales/uz.json+++ b/client/src/i18n/locales/uz.json@@ -67,6 +67,7 @@"confirm": "Tasdiqlang","copy": "Nusxalash","copied": "Ko‘chirildi",+ "copyFailed": "Nusxalab bo‘lmadi — matnni tanlab, qo‘lda nusxalang","show": "Ko'rsatish","hide": "Yashirish","apply": "Murojaat qiling",diff --git a/client/src/i18n/locales/vi.json b/client/src/i18n/locales/vi.jsonindex e01557cf..3ecb3d4d 100644--- a/client/src/i18n/locales/vi.json+++ b/client/src/i18n/locales/vi.json@@ -67,6 +67,7 @@"confirm": "Xác nhận","copy": "Sao chép","copied": "Đã sao chép",+ "copyFailed": "Không thể sao chép — hãy chọn văn bản và sao chép thủ công","show": "Hiển thị","hide": "Ẩn","apply": "Áp dụng",diff --git a/client/src/i18n/locales/yo.json b/client/src/i18n/locales/yo.jsonindex 48f03264..0cef1bf8 100644--- a/client/src/i18n/locales/yo.json+++ b/client/src/i18n/locales/yo.json@@ -67,6 +67,7 @@"confirm": "Jẹrisi","copy": "Daakọ","copied": "Ti daakọ",+ "copyFailed": "Kò ṣeé daakọ — yan ọ̀rọ̀ náà kí o sì daakọ pẹ̀lú ọwọ́","show": "Fihan","hide": "Tọju","apply": "Waye",diff --git a/client/src/i18n/locales/zh-CN.json b/client/src/i18n/locales/zh-CN.jsonindex 8b752541..661bb3c6 100644--- a/client/src/i18n/locales/zh-CN.json+++ b/client/src/i18n/locales/zh-CN.json@@ -67,6 +67,7 @@"confirm": "确认","copy": "复制","copied": "已复制",+ "copyFailed": "无法复制 — 请手动选择文本并复制","show": "显示","hide": "隐藏","apply": "应用",diff --git a/client/src/i18n/locales/zh-TW.json b/client/src/i18n/locales/zh-TW.jsonindex 2e7fded0..315cacc7 100644--- a/client/src/i18n/locales/zh-TW.json+++ b/client/src/i18n/locales/zh-TW.json@@ -67,6 +67,7 @@"confirm": "確認","copy": "複製","copied": "已複製",+ "copyFailed": "無法複製 — 請手動選取文字並複製","show": "顯示","hide": "隱藏","apply": "套用",diff --git a/client/src/lib/clipboard.test.ts b/client/src/lib/clipboard.test.tsnew file mode 100644index 00000000..bcb194a3--- /dev/null+++ b/client/src/lib/clipboard.test.ts@@ -0,0 +1,83 @@+import { describe, it, expect, vi, afterEach } from 'vitest'+import { copyText } from './clipboard'++// The tests run in the default node environment (no jsdom), so `document` and+// `navigator` are stubbed by hand — enough of each for the two copy paths.+function stubDocument(execCommandResult: boolean | (() => boolean)) {+ const selected: string[] = []+ const appended: unknown[] = []+ const removed: unknown[] = []+ const body = {+ appendChild: (node: unknown) => { appended.push(node) },+ }+ const doc = {+ body,+ createElement: () => ({+ value: '',+ style: {} as Record<string, string>,+ setAttribute: () => {},+ select: () => { selected.push('select') },+ setSelectionRange: () => {},+ remove() { removed.push(this) },+ }),+ getSelection: () => null,+ execCommand: () => (typeof execCommandResult === 'function' ? execCommandResult() : execCommandResult),+ }+ vi.stubGlobal('document', doc)+ return { appended, removed, selected }+}++afterEach(() => {+ vi.unstubAllGlobals()+})++describe('copyText', () => {+ it('uses the async Clipboard API in a secure context', async () => {+ const writeText = vi.fn().mockResolvedValue(undefined)+ vi.stubGlobal('navigator', { clipboard: { writeText } })+ const { appended } = stubDocument(true)++ expect(await copyText('sk-secret')).toBe(true)+ expect(writeText).toHaveBeenCalledWith('sk-secret')+ // The fallback must not run when the real API worked.+ expect(appended).toHaveLength(0)+ })++ // #734: navigator.clipboard is undefined on an insecure origin, which is what+ // a plain-HTTP LAN install (http://192.168.1.50:4001) is.+ it('falls back to execCommand when there is no Clipboard API', async () => {+ vi.stubGlobal('navigator', {})+ const { appended, removed, selected } = stubDocument(true)++ expect(await copyText('sk-secret')).toBe(true)+ expect(selected).toEqual(['select'])+ // The scratch textarea is always cleaned up.+ expect(appended).toHaveLength(1)+ expect(removed).toEqual(appended)+ })++ it('falls back when the Clipboard API rejects (denied permission)', async () => {+ const writeText = vi.fn().mockRejectedValue(new Error('NotAllowedError'))+ vi.stubGlobal('navigator', { clipboard: { writeText } })+ const { appended } = stubDocument(true)++ expect(await copyText('sk-secret')).toBe(true)+ expect(appended).toHaveLength(1)+ })++ it('reports failure when both paths fail, so callers do not claim success', async () => {+ vi.stubGlobal('navigator', {})+ const { removed } = stubDocument(false)++ expect(await copyText('sk-secret')).toBe(false)+ expect(removed).toHaveLength(1)+ })++ it('reports failure — and still cleans up — when execCommand throws', async () => {+ vi.stubGlobal('navigator', {})+ const { removed } = stubDocument(() => { throw new Error('unsupported') })++ expect(await copyText('sk-secret')).toBe(false)+ expect(removed).toHaveLength(1)+ })+})diff --git a/client/src/lib/clipboard.ts b/client/src/lib/clipboard.tsnew file mode 100644index 00000000..820eb7cc--- /dev/null+++ b/client/src/lib/clipboard.ts@@ -0,0 +1,55 @@+// Copy to clipboard, on secure and insecure origins alike (#734).+//+// `navigator.clipboard` only exists in a secure context. A LAN install served+// over plain HTTP — http://192.168.1.50:4001, the documented Docker setup — is+// not one, so the async Clipboard API is simply `undefined` there: every copy+// button either threw or silently did nothing while still flashing "Copied".+//+// The textarea + execCommand path is deprecated but is the only thing that+// works on an insecure origin, and every browser still supports it. It has to+// run inside the user gesture that triggered the copy, so callers must not+// await anything before calling this.+export async function copyText(text: string): Promise<boolean> {+ try {+ if (navigator.clipboard?.writeText) {+ await navigator.clipboard.writeText(text)+ return true+ }+ } catch {+ // Permission denied, or the document was not focused. Fall through.+ }+ return legacyCopy(text)+}++function legacyCopy(text: string): boolean {+ if (typeof document === 'undefined' || !document.body) return false++ const area = document.createElement('textarea')+ area.value = text+ // Off-screen but still selectable: display:none or visibility:hidden would+ // make the selection — and therefore the copy — a no-op. readonly keeps the+ // mobile keyboard from popping up during the flicker.+ area.setAttribute('readonly', '')+ area.style.position = 'fixed'+ area.style.top = '0'+ area.style.left = '-9999px'+ document.body.appendChild(area)++ // Copying steals the selection, so put back whatever the user had selected.+ const selection = document.getSelection()+ const previous = selection && selection.rangeCount > 0 ? selection.getRangeAt(0) : null++ try {+ area.select()+ area.setSelectionRange(0, text.length)+ return document.execCommand('copy')+ } catch {+ return false+ } finally {+ area.remove()+ if (previous && selection) {+ selection.removeAllRanges()+ selection.addRange(previous)+ }+ }+}diff --git a/docs/install.md b/docs/install.mdindex 6f6467f6..8a976f81 100644--- a/docs/install.md+++ b/docs/install.md@@ -183,6 +183,8 @@ docker compose logs -f freellmapiBy default the container's port is bound to `127.0.0.1` (localhost only). To reach the dashboard/API from another machine on your network, publish it on all interfaces with `HOST_BIND=0.0.0.0 docker compose up -d` — only on a trusted LAN, since the proxy is single-user.+Plain HTTP over a LAN address works as-is: the security headers that only apply to HTTPS (`upgrade-insecure-requests`, `Cross-Origin-Opener-Policy`, `Origin-Agent-Cluster`) are emitted only when the request actually arrived over TLS — or over loopback, which browsers already treat as a secure context. Behind an HTTPS reverse proxy they come back on automatically, as long as the proxy forwards `X-Forwarded-Proto`. `CSP_UPGRADE_INSECURE_REQUESTS=true|false` overrides the upgrade directive if your setup needs it.+SQLite data is stored in the `freellmapi-data` volume at `/app/server/data`.Keep the same `.env` `ENCRYPTION_KEY` and volume when upgrading, becauseprovider keys are encrypted at rest. If your host only persists a specificdiff --git a/server/src/__tests__/routes/csp-security.test.ts b/server/src/__tests__/routes/csp-security.test.tsindex ac09565b..62419076 100644--- a/server/src/__tests__/routes/csp-security.test.ts+++ b/server/src/__tests__/routes/csp-security.test.ts@@ -1,17 +1,39 @@import { describe, it, expect, beforeAll, afterAll } from 'vitest';+import http from 'node:http';import type { Express } from 'express';import { createApp } from '../../app.js';import { initDb } from '../../db/index.js';import { loadConfig } from '../../lib/config.js';-async function getHeaders(app: Express, path: string, forwardedProto?: string): Promise<Headers> {+async function getHeaders(+ app: Express,+ path: string,+ forwardedProto?: string,+ host?: string,+): Promise<Headers> {const server = app.listen(0);const addr = server.address() as any;const headers: Record<string, string> = {};if (forwardedProto) headers['x-forwarded-proto'] = forwardedProto;- const res = await fetch(`http://127.0.0.1:${addr.port}${path}`, { headers });- server.close();- return res.headers;+ // Overriding Host is how a LAN/reverse-proxy origin is simulated without+ // actually binding to one: req.hostname reads it. node:http rather than+ // fetch(), because undici silently overwrites Host with the connect target.+ if (host) headers['host'] = host;+ try {+ return await new Promise<Headers>((resolve, reject) => {+ const req = http.request(+ { host: '127.0.0.1', port: addr.port, path, headers },+ res => {+ res.resume();+ resolve(new Headers(res.headers as Record<string, string>));+ },+ );+ req.on('error', reject);+ req.end();+ });+ } finally {+ server.close();+ }}describe('CSP security headers', () => {@@ -78,6 +100,50 @@ describe('CSP upgrade-insecure-requests (#682)', () => {});});+// #734: COOP and Origin-Agent-Cluster apply to secure contexts only. Sending+// them to a plain-HTTP LAN origin gets them discarded with a console error, so+// they are emitted only where the browser would honour them.+describe('secure-context-only headers (#734)', () => {+ let app: Express;++ beforeAll(() => {+ process.env.ENCRYPTION_KEY = '0'.repeat(64);+ initDb(':memory:');+ app = createApp();+ });++ it('omits COOP and Origin-Agent-Cluster on a plain-HTTP LAN origin', async () => {+ const headers = await getHeaders(app, '/api/ping', undefined, '192.168.3.50:4001');+ expect(headers.get('cross-origin-opener-policy')).toBeNull();+ expect(headers.get('origin-agent-cluster')).toBeNull();+ });++ it('keeps them on loopback, which is a secure context over plain HTTP', async () => {+ for (const host of ['localhost:3001', '127.0.0.1:3001', 'freellmapi.localhost']) {+ const headers = await getHeaders(app, '/api/ping', undefined, host);+ expect(headers.get('cross-origin-opener-policy'), host).toBe('same-origin');+ expect(headers.get('origin-agent-cluster'), host).toBe('?1');+ }+ });++ it('keeps them behind an HTTPS reverse proxy', async () => {+ const headers = await getHeaders(app, '/api/ping', 'https', 'proxy.example.com');+ expect(headers.get('cross-origin-opener-policy')).toBe('same-origin');+ expect(headers.get('origin-agent-cluster')).toBe('?1');+ });++ it('reads the client-facing hop from a multi-proxy X-Forwarded-Proto', async () => {+ const headers = await getHeaders(app, '/api/ping', 'https, http', 'proxy.example.com');+ expect(headers.get('cross-origin-opener-policy')).toBe('same-origin');+ expect(headers.get('content-security-policy')).toContain('upgrade-insecure-requests');+ });++ it('leaves Cross-Origin-Resource-Policy alone (it is not secure-context gated)', async () => {+ const headers = await getHeaders(app, '/api/ping', undefined, '192.168.3.50:4001');+ expect(headers.get('cross-origin-resource-policy')).toBe('same-origin');+ });+});+describe('CSP_UPGRADE_INSECURE_REQUESTS env override (#682)', () => {let app: Express;const envKey = 'CSP_UPGRADE_INSECURE_REQUESTS';diff --git a/server/src/app.ts b/server/src/app.tsindex f3cce45b..3b1f3bdd 100644--- a/server/src/app.ts+++ b/server/src/app.ts@@ -64,6 +64,29 @@ function isImmutableAsset(filePath: string): boolean {);}+// Loopback and *.localhost are "potentially trustworthy" origins even over+// plain HTTP (https://www.w3.org/TR/powerful-features/#is-origin-trustworthy),+// so a desktop/localhost install still gets the secure-context-only headers.+const LOOPBACK_HOST_RE = /^(?:localhost|[^.]+(?:\.[^.]+)*\.localhost|127(?:\.\d{1,3}){3}|\[?::1\]?)$/i;++// TLS terminated here (req.secure), or in front of us and forwarded. The+// X-Forwarded-Proto check is the documented reverse-proxy setup for publishing+// the proxy beyond localhost.+function isHttpsRequest(req: express.Request): boolean {+ const forwardedProto = req.headers['x-forwarded-proto'];+ // A proxy chain sends a comma-separated list; the client-facing hop is first.+ const first = String(forwardedProto ?? '').split(',')[0]!.trim().toLowerCase();+ return first === 'https' || req.secure;+}++// Whether the browser will treat this origin as a secure context. Headers that+// only apply to secure contexts are worse than useless elsewhere: the browser+// drops them and logs an error, which is exactly what a plain-HTTP LAN install+// reported in #734.+function isTrustworthyOrigin(req: express.Request): boolean {+ return isHttpsRequest(req) || LOOPBACK_HOST_RE.test(req.hostname ?? '');+}+export function createApp(config?: Config) {const cfg = config ?? loadConfig();const app = express();@@ -83,6 +106,12 @@ export function createApp(config?: Config) {// producing ERR_SSL_PROTOCOL_ERROR and a blank dashboard (#682).// The directive is dropped from the static Helmet config and re-added per// request below, gated by protocol + the CSP_UPGRADE_INSECURE_REQUESTS env.+ //+ // Cross-Origin-Opener-Policy and Origin-Agent-Cluster are handled the same+ // way, for the same reason: both only apply to secure contexts, so on a+ // plain-HTTP LAN origin the browser discards them and logs a console error+ // instead (#734). They are re-added per request whenever the origin is one+ // the browser trusts — HTTPS, or loopback, which covers desktop/localhost.app.use(helmet({contentSecurityPolicy: {directives: {@@ -104,22 +133,22 @@ export function createApp(config?: Config) {},},hsts: false,+ crossOriginOpenerPolicy: false,+ originAgentCluster: false,}));- // Per-request CSP re-issue: only HTTPS origins should tell the browser to- // upgrade http→https, since plain-HTTP LAN setups have no TLS to upgrade to.- // `req.secure` is true when the TLS socket terminated on this server; the- // X-Forwarded-Proto check covers HTTPS reverse proxies (the documented setup- // for publishing the proxy beyond localhost). The env flag overrides both.- // Helmet ran above and synchronously set the CSP header on res; this runs- // next, still before any route handler writes the body, so setHeader here- // lands before the response is flushed.+ // Per-request re-issue of the headers that depend on how the page was+ // reached. Only HTTPS origins should tell the browser to upgrade http→https,+ // since plain-HTTP LAN setups have no TLS to upgrade to; the env flag+ // overrides that either way. COOP and Origin-Agent-Cluster go back on for any+ // origin the browser considers trustworthy (HTTPS or loopback), which is+ // every origin that would have honoured them in the first place.+ // Helmet ran above and synchronously set its headers on res; this runs next,+ // still before any route handler writes the body, so setHeader here lands+ // before the response is flushed.app.use((req, res, next) => {- const forwardedProto = req.headers['x-forwarded-proto'];- const isHttps =- String(forwardedProto ?? '').toLowerCase().startsWith('https') || req.secure;const shouldEmit =cfg.cspUpgradeInsecureRequests === true ||- (cfg.cspUpgradeInsecureRequests === undefined && isHttps);+ (cfg.cspUpgradeInsecureRequests === undefined && isHttpsRequest(req));if (shouldEmit) {const csp = res.getHeader('content-security-policy');@@ -128,6 +157,11 @@ export function createApp(config?: Config) {}}+ if (isTrustworthyOrigin(req)) {+ res.setHeader('Cross-Origin-Opener-Policy', 'same-origin');+ res.setHeader('Origin-Agent-Cluster', '?1');+ }+next();});app.use(cors({