From 418f38829a34ef362bb0c165362a54e7804c63f3 Mon Sep 17 00:00:00 2001 From: Divyam Talwar Date: Tue, 30 Jun 2026 05:41:29 +0530 Subject: [PATCH] Reduce exposure of bearer connection values during UI debugging Connection URI debug logs could include morphik:// values, parsed auth tokens, and connection-derived URLs. Keep event-level debug messages while removing the credential-bearing values. Constraint: Morphik connection URIs can carry bearer credentials. Rejected: Removing all UI debug logging | event-only messages preserve useful local diagnosis without printing secrets. Confidence: high Scope-risk: narrow Directive: Do not add URI or token values back to browser console output; log booleans or connection types only. Tested: npm install --package-lock=false; npx next lint --file contexts/morphik-context.tsx --file lib/connection-utils.ts --file lib/utils.ts; npx prettier --check contexts/morphik-context.tsx lib/connection-utils.ts lib/utils.ts; npx tsc --noEmit --pretty false; credential-bearing console value grep; git diff --check. Not-tested: npm run lint and npm run build still fail on pre-existing unrelated UI lint issues in components/ui/button.tsx and components/ui/sheet.tsx. --- ee/ui-component/contexts/morphik-context.tsx | 31 ++++++++++++-------- ee/ui-component/lib/connection-utils.ts | 6 ++-- ee/ui-component/lib/utils.ts | 12 +++----- 3 files changed, 26 insertions(+), 23 deletions(-) diff --git a/ee/ui-component/contexts/morphik-context.tsx b/ee/ui-component/contexts/morphik-context.tsx index d82a8324..f38872a8 100644 --- a/ee/ui-component/contexts/morphik-context.tsx +++ b/ee/ui-component/contexts/morphik-context.tsx @@ -38,7 +38,9 @@ function getStoredConnectionUri(): string | null { if (stored && stored.includes("://morphik://")) { // Remove the leading protocol from malformed URIs like https://morphik://... const cleaned = stored.replace(/^https?:\/\//, ""); - console.log("Cleaning malformed stored URI:", stored, "→", cleaned); + console.log("Cleaning malformed stored connection URI", { + hadHttpProtocolPrefix: /^https?:\/\//.test(stored), + }); window.localStorage.setItem(CONNECTION_URI_STORAGE_KEY, cleaned); return cleaned; } @@ -49,7 +51,10 @@ function getStoredConnectionUri(): string | null { const match = stored.match(/^morphik:\/\/local@(.+)$/); if (match && match[1]) { const migratedUri = match[1]; - console.log("Migrating old URI format:", stored, "→", migratedUri); + console.log("Migrating stored local connection URI format", { + from: "morphik-local", + to: "host", + }); // Update storage with migrated value window.localStorage.setItem(CONNECTION_URI_STORAGE_KEY, migratedUri); return migratedUri; @@ -106,7 +111,7 @@ export function MorphikProvider({ // Clear stored URI if it's a local connection (on app restart) if (storedUri && isLocalUri(storedUri)) { - console.log("Clearing stored local connection URI on app restart:", storedUri); + console.log("Clearing stored local connection URI on app restart"); setStoredConnectionUri(null); // Use initial value or external prop for local connections return externalConnectionUri || initialConnectionUri; @@ -133,7 +138,11 @@ export function MorphikProvider({ // Safety check: ensure it's a proper HTTP(S) URL if (!url.startsWith("http://") && !url.startsWith("https://")) { - console.error("[MorphikContext] Invalid apiBaseUrl:", url); + console.error("[MorphikContext] Invalid apiBaseUrl", { + hasValue: Boolean(connectionInfo.apiBaseUrl), + hasHttpProtocol: url.startsWith("http://"), + hasHttpsProtocol: url.startsWith("https://"), + }); return DEFAULT_API_BASE_URL; } @@ -161,7 +170,7 @@ export function MorphikProvider({ } else if (connectionUri && connectionInfo && connectionInfo.type === "local") { // For local connections, we can optionally store temporarily // but it will be cleared on next app restart - console.log("Local connection - will be cleared on restart:", connectionUri); + console.log("Local connection will be cleared on restart"); setStoredConnectionUri(connectionUri); } else { // Clear storage if no URI @@ -171,21 +180,17 @@ export function MorphikProvider({ const updateConnectionUri = (uri: string) => { if (!isReadOnlyUri) { - console.log("[MorphikContext] updateConnectionUri:", uri); + console.log("[MorphikContext] updateConnectionUri"); setConnectionUri(uri); } }; // Debug log when values change React.useEffect(() => { - console.log("[MorphikContext] Current values:", { - connectionUri, - connectionInfo, - apiBaseUrl, - authToken, - isLocal, + console.log("[MorphikContext] Connection state changed:", { + hasConnection: Boolean(connectionUri), }); - }, [connectionUri, connectionInfo, apiBaseUrl, authToken, isLocal]); + }, [connectionUri]); return (