Turn any website into a lightweight desktop app with one command, on macOS, Windows and Linux.
Rust chatgptclaudeclidesktopdesktop-appelectron-alternativegeminilinuxmacosnativefierno-electronrusttauriweb-to-desktopwebsite-to-appwebviewwindowsyoutube
feat: support enterprise SSO navigation
Xan Torres30e35f2693fd
diff --git a/bin/defaults.ts b/bin/defaults.tsindex c927754d..a77d3a93 100644--- a/bin/defaults.ts+++ b/bin/defaults.ts@@ -44,6 +44,7 @@ export const DEFAULT_PAKE_OPTIONS: PakeCliOptions = {startToTray: false,forceInternalNavigation: false,internalUrlRegex: '',+ safeDomain: '',enableFind: false,iterativeBuild: false,zoom: 100,diff --git a/bin/helpers/cli-program.ts b/bin/helpers/cli-program.tsindex 8d84e1ff..a806f13f 100644--- a/bin/helpers/cli-program.ts+++ b/bin/helpers/cli-program.ts@@ -184,17 +184,19 @@ ${green('|_| \\__,_|_|\\_\\___| can turn any webpage into a desktop app withnew Option('--force-internal-navigation','Keep every link inside the Pake window instead of opening external handlers',- )- .default(DEFAULT.forceInternalNavigation)- .hideHelp(),+ ).default(DEFAULT.forceInternalNavigation),).addOption(new Option('--internal-url-regex <string>','Regex pattern to match URLs that should be considered internal',- )- .default(DEFAULT.internalUrlRegex)- .hideHelp(),+ ).default(DEFAULT.internalUrlRegex),+ )+ .addOption(+ new Option(+ '--safe-domain <domains>',+ 'Comma-separated domains kept inside the app (e.g. SSO/workspace callbacks)',+ ).default(DEFAULT.safeDomain),).addOption(new Option(@@ -253,9 +255,7 @@ ${green('|_| \\__,_|_|\\_\\___| can turn any webpage into a desktop app withnew Option('--new-window','Allow sites to open new windows (for auth flows, tabs, branches)',- )- .default(DEFAULT.newWindow)- .hideHelp(),+ ).default(DEFAULT.newWindow),).addOption(new Option(diff --git a/bin/options/index.ts b/bin/options/index.tsindex bcb6a0aa..73fb4955 100644--- a/bin/options/index.ts+++ b/bin/options/index.ts@@ -3,7 +3,7 @@ import fsExtra from 'fs-extra';import logger from '@/options/logger';import { handleIcon } from './icon';-import { getDomain } from '@/utils/url';+import { getDomain, safeDomainsToRegex } from '@/utils/url';import {promptText,capitalizeFirstLetter,@@ -86,6 +86,11 @@ export default async function handleOptions(identifier: resolveIdentifier(url, options.name, options.identifier),};+ // --safe-domain is sugar over --internal-url-regex; an explicit regex wins.+ if (!options.internalUrlRegex && options.safeDomain) {+ appOptions.internalUrlRegex = safeDomainsToRegex(options.safeDomain);+ }+const iconPath = await handleIcon(appOptions, url);appOptions.icon = iconPath || '';diff --git a/bin/types.ts b/bin/types.tsindex cb53715f..bd966477 100644--- a/bin/types.ts+++ b/bin/types.ts@@ -108,6 +108,9 @@ export interface PakeCliOptions {// Regex pattern to match URLs that should be considered internalinternalUrlRegex: string;+ // Comma-separated domains kept inside the app, compiled into internalUrlRegex, default empty+ safeDomain: string;+// Enable in-page Find UI and Cmd/Ctrl+F/G shortcuts, default falseenableFind: boolean;diff --git a/bin/utils/url.ts b/bin/utils/url.tsindex 18292ba4..0bfca9dc 100644--- a/bin/utils/url.ts+++ b/bin/utils/url.ts@@ -40,3 +40,18 @@ export function normalizeUrl(urlToNormalize: string): string {);}}++// Compiles a comma-separated domain list into a regex source for+// internal_url_regex. Each domain is escaped and matched against the URL host+// and its subdomains so path or query text cannot accidentally opt a link in.+// Returns '' for empty input.+export function safeDomainsToRegex(domains: string): string {+ const escaped = domains+ .split(',')+ .map((domain) => domain.trim().toLowerCase())+ .filter(Boolean)+ .map((domain) => domain.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'));+ return escaped.length+ ? `^https?:\\/\\/(?:[^/?#@]+\\.)*(?:${escaped.join('|')})(?::\\d+)?(?:[/?#]|$)`+ : '';+}diff --git a/dist/cli.js b/dist/cli.jsindex 3fda6860..9602cc5a 100644--- a/dist/cli.js+++ b/dist/cli.js@@ -2446,6 +2446,20 @@ function normalizeUrl(urlToNormalize) {throw new Error(`Your url "${urlWithProtocol}" is invalid: ${err.message}`);}}+// Compiles a comma-separated domain list into a regex source for+// internal_url_regex. Each domain is escaped and matched against the URL host+// and its subdomains so path or query text cannot accidentally opt a link in.+// Returns '' for empty input.+function safeDomainsToRegex(domains) {+ const escaped = domains+ .split(',')+ .map((domain) => domain.trim().toLowerCase())+ .filter(Boolean)+ .map((domain) => domain.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'));+ return escaped.length+ ? `^https?:\\/\\/(?:[^/?#@]+\\.)*(?:${escaped.join('|')})(?::\\d+)?(?:[/?#]|$)`+ : '';+}/*** Error class used for user-facing CLI errors.@@ -2526,6 +2540,10 @@ async function handleOptions(options, url) {name: resolvedName,identifier: resolveIdentifier(url, options.name, options.identifier),};+ // --safe-domain is sugar over --internal-url-regex; an explicit regex wins.+ if (!options.internalUrlRegex && options.safeDomain) {+ appOptions.internalUrlRegex = safeDomainsToRegex(options.safeDomain);+ }const iconPath = await handleIcon(appOptions, url);appOptions.icon = iconPath || '';return appOptions;@@ -2574,6 +2592,7 @@ const DEFAULT_PAKE_OPTIONS = {startToTray: false,forceInternalNavigation: false,internalUrlRegex: '',+ safeDomain: '',enableFind: false,iterativeBuild: false,zoom: 100,@@ -2715,12 +2734,9 @@ ${green('|_| \\__,_|_|\\_\\___| can turn any webpage into a desktop app with.addOption(new Option('--start-to-tray', 'Start app minimized to tray').default(DEFAULT_PAKE_OPTIONS.startToTray).hideHelp())- .addOption(new Option('--force-internal-navigation', 'Keep every link inside the Pake window instead of opening external handlers')- .default(DEFAULT_PAKE_OPTIONS.forceInternalNavigation)- .hideHelp())- .addOption(new Option('--internal-url-regex <string>', 'Regex pattern to match URLs that should be considered internal')- .default(DEFAULT_PAKE_OPTIONS.internalUrlRegex)- .hideHelp())+ .addOption(new Option('--force-internal-navigation', 'Keep every link inside the Pake window instead of opening external handlers').default(DEFAULT_PAKE_OPTIONS.forceInternalNavigation))+ .addOption(new Option('--internal-url-regex <string>', 'Regex pattern to match URLs that should be considered internal').default(DEFAULT_PAKE_OPTIONS.internalUrlRegex))+ .addOption(new Option('--safe-domain <domains>', 'Comma-separated domains kept inside the app (e.g. SSO/workspace callbacks)').default(DEFAULT_PAKE_OPTIONS.safeDomain)).addOption(new Option('--enable-find', 'Enable in-page Find UI with Cmd/Ctrl+F/G shortcuts').default(DEFAULT_PAKE_OPTIONS.enableFind).hideHelp())@@ -2751,9 +2767,7 @@ ${green('|_| \\__,_|_|\\_\\___| can turn any webpage into a desktop app with.addOption(new Option('--iterative-build', 'Turn on rapid build mode (app only, no dmg/deb/msi), good for debugging').default(DEFAULT_PAKE_OPTIONS.iterativeBuild).hideHelp())- .addOption(new Option('--new-window', 'Allow sites to open new windows (for auth flows, tabs, branches)')- .default(DEFAULT_PAKE_OPTIONS.newWindow)- .hideHelp())+ .addOption(new Option('--new-window', 'Allow sites to open new windows (for auth flows, tabs, branches)').default(DEFAULT_PAKE_OPTIONS.newWindow)).addOption(new Option('--install', 'Auto-install app to /Applications (macOS) after build and remove local bundle').default(DEFAULT_PAKE_OPTIONS.install).hideHelp())diff --git a/src-tauri/src/inject/auth.js b/src-tauri/src/inject/auth.jsindex c045baa0..3d9140df 100644--- a/src-tauri/src/inject/auth.js+++ b/src-tauri/src/inject/auth.js@@ -17,6 +17,12 @@ function matchesAuthUrl(url, baseUrl = window.location.href) {/facebook\.com\/.*\/dialog/,/twitter\.com\/oauth/,/appleid\.apple\.com/,+ // Enterprise SSO providers and SAML/ADFS endpoints+ /\.okta\.com/,+ /\.onelogin\.com/,+ /\/saml\//,+ /\/sso\//,+ /adfs\/ls/,/\/oauth\//,/\/auth\//,/\/authorize/,diff --git a/src-tauri/src/inject/event.js b/src-tauri/src/inject/event.jsindex 163ebd38..40ea29ae 100644--- a/src-tauri/src/inject/event.js+++ b/src-tauri/src/inject/event.js@@ -459,20 +459,23 @@ document.addEventListener("DOMContentLoaded", () => {const absoluteUrl = hrefUrl.href;let filename = anchorElement.download || getFilenameFromUrl(absoluteUrl);- // Keep OAuth/authentication flows inside the app when popup support is enabled.+ // Keep OAuth/authentication flows inside the app. Without --new-window,+ // navigate in place so the SSO redirect chain and callback stay in the+ // webview instead of falling through to the system browser.if (window.isAuthLink(absoluteUrl)) {console.log("[Pake] Handling OAuth navigation in-app:", absoluteUrl);+ e.preventDefault();+ e.stopImmediatePropagation();if (window.pakeConfig?.new_window) {- e.preventDefault();- e.stopImmediatePropagation();-openAuthNavigation(originalWindowOpen,absoluteUrl,"_blank","width=1200,height=800,scrollbars=yes,resizable=yes",);+ } else {+ window.location.href = absoluteUrl;}return;@@ -488,7 +491,15 @@ document.addEventListener("DOMContentLoaded", () => {}if (isInternalUrl(absoluteUrl)) {- // For internal links (based on regex or domain), let the browser handle it naturally+ // With --new-window the Rust on_new_window handler opens an in-app+ // window; without it, deferring to the native handler sends the+ // _blank target to the system browser and strands SSO callbacks.+ // Navigate in place so internal links stay inside the webview.+ if (!window.pakeConfig?.new_window) {+ e.preventDefault();+ e.stopImmediatePropagation();+ window.location.href = absoluteUrl;+ }return;}@@ -592,6 +603,14 @@ document.addEventListener("DOMContentLoaded", () => {return null;}+ // With --new-window the native handler opens an in-app window; without it,+ // originalWindowOpen would route the internal target to the system browser+ // and strand SSO callbacks, so navigate in place instead.+ if (!window.pakeConfig?.new_window) {+ window.location.href = absoluteUrl;+ return window;+ }+return originalWindowOpen.call(window, absoluteUrl, name, specs);} catch (error) {return originalWindowOpen.call(window, url, name, specs);diff --git a/tests/unit/auth-sso-patterns.test.js b/tests/unit/auth-sso-patterns.test.jsnew file mode 100644index 00000000..95fbd407--- /dev/null+++ b/tests/unit/auth-sso-patterns.test.js@@ -0,0 +1,50 @@+import fs from "fs";+import path from "path";+import { runInNewContext } from "node:vm";+import { describe, expect, it } from "vitest";++function loadAuthHelpers() {+ const source = fs.readFileSync(+ path.join(process.cwd(), "src-tauri/src/inject/auth.js"),+ "utf-8",+ );++ const context = {+ console,+ URL,+ window: {+ location: { href: "https://example.com/app" },+ },+ };++ runInNewContext(source, context);+ return context.window;+}++describe("auth SSO patterns", () => {+ const { isAuthLink, isAuthPopup } = loadAuthHelpers();++ it("matches enterprise SSO providers and endpoints", () => {+ expect(isAuthLink("https://mycompany.okta.com/app/sign-on")).toBe(true);+ expect(isAuthLink("https://acme.onelogin.com/login")).toBe(true);+ expect(isAuthLink("https://idp.example.com/saml/acs")).toBe(true);+ expect(isAuthLink("https://idp.example.com/sso/redirect")).toBe(true);+ expect(isAuthLink("https://fs.example.com/adfs/ls/?wa=wsignin1.0")).toBe(+ true,+ );+ });++ it("still matches the original OAuth providers", () => {+ expect(isAuthLink("https://accounts.google.com/o/oauth2/auth")).toBe(true);+ expect(isAuthLink("https://login.microsoftonline.com/common")).toBe(true);+ });++ it("does not flag ordinary application URLs", () => {+ expect(isAuthLink("https://example.com/dashboard")).toBe(false);+ expect(isAuthLink("https://example.com/reports/q3")).toBe(false);+ });++ it("treats known auth window names as popups", () => {+ expect(isAuthPopup("https://example.com/dashboard", "oauth2")).toBe(true);+ });+});diff --git a/tests/unit/cli-options.test.ts b/tests/unit/cli-options.test.tsindex 51dcbe3d..0b8a3376 100644--- a/tests/unit/cli-options.test.ts+++ b/tests/unit/cli-options.test.ts@@ -29,13 +29,42 @@ describe('CLI options', () => {expect(option?.defaultValue).toBe(false);});- it('registers hidden --internal-url-regex option', () => {+ it('exposes --internal-url-regex option', () => {const option = program.options.find((item) => item.long === '--internal-url-regex',);expect(option).toBeDefined();expect(option?.defaultValue).toBe('');+ expect(option?.hidden).toBeFalsy();+ });++ it('exposes --safe-domain option', () => {+ const option = program.options.find(+ (item) => item.long === '--safe-domain',+ );++ expect(option).toBeDefined();+ expect(option?.defaultValue).toBe('');+ expect(option?.hidden).toBeFalsy();+ });++ it('exposes --force-internal-navigation option', () => {+ const option = program.options.find(+ (item) => item.long === '--force-internal-navigation',+ );++ expect(option).toBeDefined();+ expect(option?.defaultValue).toBe(false);+ expect(option?.hidden).toBeFalsy();+ });++ it('exposes --new-window option', () => {+ const option = program.options.find((item) => item.long === '--new-window');++ expect(option).toBeDefined();+ expect(option?.defaultValue).toBe(false);+ expect(option?.hidden).toBeFalsy();});it('registers hidden --identifier option', () => {diff --git a/tests/unit/safe-domains.test.ts b/tests/unit/safe-domains.test.tsnew file mode 100644index 00000000..580cc551--- /dev/null+++ b/tests/unit/safe-domains.test.ts@@ -0,0 +1,55 @@+import { describe, expect, it } from 'vitest';+import { safeDomainsToRegex } from '../../bin/utils/url.js';++describe('safeDomainsToRegex', () => {+ it('builds a host-bound regex for a single domain', () => {+ expect(safeDomainsToRegex('slack.com')).toBe(+ '^https?:\\/\\/(?:[^/?#@]+\\.)*(?:slack\\.com)(?::\\d+)?(?:[/?#]|$)',+ );+ });++ it('joins multiple domains with alternation', () => {+ expect(safeDomainsToRegex('slack.com,acme.com')).toBe(+ '^https?:\\/\\/(?:[^/?#@]+\\.)*(?:slack\\.com|acme\\.com)(?::\\d+)?(?:[/?#]|$)',+ );+ });++ it('trims whitespace and drops empty entries', () => {+ expect(safeDomainsToRegex(' slack.com , , acme.com ')).toBe(+ '^https?:\\/\\/(?:[^/?#@]+\\.)*(?:slack\\.com|acme\\.com)(?::\\d+)?(?:[/?#]|$)',+ );+ });++ it('returns an empty string for blank input', () => {+ expect(safeDomainsToRegex('')).toBe('');+ expect(safeDomainsToRegex(' , , ')).toBe('');+ });++ it('escapes regex metacharacters in domains', () => {+ expect(safeDomainsToRegex('a.b+c')).toBe(+ '^https?:\\/\\/(?:[^/?#@]+\\.)*(?:a\\.b\\+c)(?::\\d+)?(?:[/?#]|$)',+ );+ });++ it('compiles to a regex that matches allowed URL hosts', () => {+ const pattern = new RegExp(safeDomainsToRegex('slack.com,okta.com'));++ expect(pattern.test('https://slack.com')).toBe(true);+ expect(pattern.test('https://mycompany.okta.com/sso')).toBe(true);+ expect(pattern.test('https://app.slack.com/client')).toBe(true);+ expect(pattern.test('https://slack.com:443/client')).toBe(true);+ expect(pattern.test('https://example.com/dashboard')).toBe(false);+ });++ it('does not match domains embedded in unrelated hosts or URL text', () => {+ const pattern = new RegExp(safeDomainsToRegex('slack.com,okta.com'));++ expect(pattern.test('https://evilslack.com')).toBe(false);+ expect(pattern.test('https://slack.com.evil.example')).toBe(false);+ expect(pattern.test('https://okta.com.evil.example/sso')).toBe(false);+ expect(+ pattern.test('https://example.com/callback?next=https://okta.com'),+ ).toBe(false);+ expect(pattern.test('https://[email protected]/sso')).toBe(false);+ });+});