Gate certificate trust proceed action on runtime capability (#9070)
Only offer 'Proceed Anyway (Unsafe)' if the connected remote runtime advertises browser.certificate-trust.v1 support. Older runtimes cannot honor the request and would fail silently, creating a false affordance. Centralize certificate error normalization to prevent divergence between main and renderer certificate matching, and unify URL redaction for Kagi session token stripping across load-error paths.
This commit is contained in:
@@ -1,15 +1,12 @@
|
||||
import { createHash } from 'node:crypto'
|
||||
|
||||
import { normalizeCertificateError } from '../../shared/browser-certificate-errors'
|
||||
|
||||
export { normalizeCertificateError }
|
||||
|
||||
export const SUPPORTED_CERTIFICATE_ERROR = 'ERR_CERT_AUTHORITY_INVALID'
|
||||
export const SUPPORTED_CERTIFICATE_ERROR_CODE = -202
|
||||
|
||||
export function normalizeCertificateError(error: string): string {
|
||||
return error
|
||||
.trim()
|
||||
.replace(/^net::/i, '')
|
||||
.toUpperCase()
|
||||
}
|
||||
|
||||
export function getSupportedCertificateErrorCode(error: string): number | null {
|
||||
return normalizeCertificateError(error) === SUPPORTED_CERTIFICATE_ERROR
|
||||
? SUPPORTED_CERTIFICATE_ERROR_CODE
|
||||
|
||||
@@ -107,7 +107,11 @@ export class BrowserCertificateTrustController {
|
||||
})
|
||||
}
|
||||
answer(false)
|
||||
} catch {
|
||||
} catch (error) {
|
||||
// Why: fail closed, but log first — a throw in challenge recording would
|
||||
// otherwise present as "the cert prompt never appears" with no trace,
|
||||
// matching the logging catch in browser-manager's guest-state notifier.
|
||||
console.error('[browser-certificate-trust-controller] handleCertificateError failed', error)
|
||||
answer(false)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -891,11 +891,11 @@ export class BrowserManager {
|
||||
return
|
||||
}
|
||||
this.clearedLoadErrorsByGuestId.delete(guest.id)
|
||||
const loadError = {
|
||||
code: errorCode,
|
||||
description: errorDescription || 'This site could not be reached.',
|
||||
validatedUrl: redactKagiSessionToken(validatedURL || guest.getURL() || 'about:blank')
|
||||
}
|
||||
const loadError = this.buildLoadError(
|
||||
errorCode,
|
||||
errorDescription || 'This site could not be reached.',
|
||||
validatedURL || guest.getURL() || 'about:blank'
|
||||
)
|
||||
this.loadErrorsByGuestId.set(guest.id, loadError)
|
||||
this.forwardOrQueueGuestLoadFailure(guest.id, loadError)
|
||||
this.notifyBrowserGuestStateChanged(guest.id)
|
||||
@@ -1299,17 +1299,24 @@ export class BrowserManager {
|
||||
}
|
||||
}
|
||||
|
||||
// Why: both the did-fail-load path and the synthesized certificate failure
|
||||
// build a load error from an untrusted URL; centralize the redaction so a
|
||||
// future third site cannot forget to strip Kagi session tokens.
|
||||
private buildLoadError(code: number, description: string, rawUrl: string): BrowserLoadError {
|
||||
return {
|
||||
code,
|
||||
description,
|
||||
validatedUrl: redactKagiSessionToken(rawUrl)
|
||||
}
|
||||
}
|
||||
|
||||
notifyCertificateFailureChanged(
|
||||
webContentsId: number,
|
||||
failure: BrowserCertificateFailure | null,
|
||||
navigationUrl?: string
|
||||
): void {
|
||||
if (failure && navigationUrl) {
|
||||
const loadError = {
|
||||
code: failure.errorCode ?? -1,
|
||||
description: failure.error,
|
||||
validatedUrl: redactKagiSessionToken(navigationUrl)
|
||||
}
|
||||
const loadError = this.buildLoadError(failure.errorCode ?? -1, failure.error, navigationUrl)
|
||||
this.loadErrorsByGuestId.set(webContentsId, loadError)
|
||||
this.forwardOrQueueGuestLoadFailure(webContentsId, loadError)
|
||||
}
|
||||
|
||||
@@ -61,6 +61,7 @@ import { Popover, PopoverAnchor, PopoverContent } from '@/components/ui/popover'
|
||||
import { useAppStore } from '@/store'
|
||||
import { getRuntimeEnvironmentIdForWorktree } from '@/lib/worktree-runtime-owner'
|
||||
import { ORCA_BROWSER_BLANK_URL, ORCA_BROWSER_PARTITION } from '../../../../shared/constants'
|
||||
import { BROWSER_CERTIFICATE_TRUST_RUNTIME_CAPABILITY } from '../../../../shared/protocol-version'
|
||||
import { getOrcaProfileBrowserDefaultPartition } from '../../../../shared/orca-profiles'
|
||||
import type {
|
||||
BrowserCertificateProceedResult,
|
||||
@@ -151,6 +152,7 @@ import {
|
||||
} from '@/runtime/runtime-file-client'
|
||||
import {
|
||||
callRuntimeRpc,
|
||||
runtimeEnvironmentSupportsCapability,
|
||||
RuntimeRpcCallError,
|
||||
type RuntimeClientTarget
|
||||
} from '@/runtime/runtime-rpc-client'
|
||||
@@ -947,6 +949,38 @@ function RemoteBrowserPagePane({
|
||||
const closeBrowserTab = useAppStore((s) => s.closeBrowserTab)
|
||||
const keybindings = useAppStore((state) => state.keybindings)
|
||||
|
||||
// Why: a remote runtime that predates browser.certificate-trust.v1 cannot
|
||||
// honor a proceed request, so the "Proceed Anyway (Unsafe)" affordance stays
|
||||
// hidden until the connected runtime positively advertises support (design
|
||||
// doc: older runtimes never show an enabled proceed action).
|
||||
const [remoteCertificateTrustSupported, setRemoteCertificateTrustSupported] = useState(false)
|
||||
const remoteCertificateEnvironmentId = remotePageHandle?.environmentId ?? null
|
||||
const certificateChallengeId = certificateFailure?.challengeId ?? null
|
||||
useEffect(() => {
|
||||
if (!remoteCertificateEnvironmentId || !certificateChallengeId) {
|
||||
setRemoteCertificateTrustSupported(false)
|
||||
return
|
||||
}
|
||||
let cancelled = false
|
||||
void runtimeEnvironmentSupportsCapability(
|
||||
remoteCertificateEnvironmentId,
|
||||
BROWSER_CERTIFICATE_TRUST_RUNTIME_CAPABILITY
|
||||
)
|
||||
.then((supported) => {
|
||||
if (!cancelled) {
|
||||
setRemoteCertificateTrustSupported(supported)
|
||||
}
|
||||
})
|
||||
.catch(() => {
|
||||
if (!cancelled) {
|
||||
setRemoteCertificateTrustSupported(false)
|
||||
}
|
||||
})
|
||||
return () => {
|
||||
cancelled = true
|
||||
}
|
||||
}, [remoteCertificateEnvironmentId, certificateChallengeId])
|
||||
|
||||
currentBrowserTabIdRef.current = browserTab.id
|
||||
currentBrowserTabUrlRef.current = browserTab.url
|
||||
activeRuntimeEnvironmentIdRef.current = activeRuntimeEnvironmentId
|
||||
@@ -2696,7 +2730,7 @@ function RemoteBrowserPagePane({
|
||||
onTryHttps={(url) => void runRemoteNavigation('browser.goto', url)}
|
||||
onCopy={(url) => void window.api.ui.writeClipboardText(url)}
|
||||
onOpenExternal={(url) => void window.api.shell.openUrl(url)}
|
||||
certificateFailure={certificateFailure}
|
||||
certificateFailure={remoteCertificateTrustSupported ? certificateFailure : null}
|
||||
expectedBrowserPageId={
|
||||
remotePageHandle?.environmentId === activeRuntimeEnvironmentId
|
||||
? remotePageHandle.remotePageId
|
||||
|
||||
@@ -10,6 +10,7 @@ import type {
|
||||
BrowserLoadError
|
||||
} from '../../../../shared/types'
|
||||
import { isEligibleLocalCertificateHost } from '../../../../shared/browser-url'
|
||||
import { normalizeCertificateError } from '../../../../shared/browser-certificate-errors'
|
||||
import {
|
||||
formatLoadFailureDescription,
|
||||
formatLoadFailureRecoveryHint,
|
||||
@@ -51,13 +52,6 @@ function getLoadErrorMetadata(loadError: BrowserLoadError): LoadFailureMeta {
|
||||
}
|
||||
}
|
||||
|
||||
function normalizeCertificateError(error: string): string {
|
||||
return error
|
||||
.trim()
|
||||
.replace(/^net::/i, '')
|
||||
.toUpperCase()
|
||||
}
|
||||
|
||||
function getMatchingCertificateFailure(args: {
|
||||
loadError: BrowserLoadError
|
||||
certificateFailure?: BrowserCertificateFailure | null
|
||||
|
||||
@@ -7,3 +7,13 @@ const CHROMIUM_CERTIFICATE_ERROR_CODES = new Set([
|
||||
export function isChromiumCertificateErrorCode(code: number): boolean {
|
||||
return CHROMIUM_CERTIFICATE_ERROR_CODES.has(code)
|
||||
}
|
||||
|
||||
// Why: main (certificate-error handler) and the renderer overlay both compare
|
||||
// Chromium error strings; keep one normalizer so their challenge-matching can
|
||||
// never silently diverge.
|
||||
export function normalizeCertificateError(error: string): string {
|
||||
return error
|
||||
.trim()
|
||||
.replace(/^net::/i, '')
|
||||
.toUpperCase()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user