Skip to content

armgit / mimik

Public Imported from GitHub
0

🎬 A browser extension and desktop app that turns your clicks into step-by-step guides with annotated screenshots πŸ“–

fix(transfer): keep spoken text and typed values out of a shared file

davbio6acd314336ad
diff --git a/src/core/transfer/__tests__/bundle.test.ts b/src/core/transfer/__tests__/bundle.test.ts
index 1dc543b..507fcf8 100644
--- a/src/core/transfer/__tests__/bundle.test.ts
+++ b/src/core/transfer/__tests__/bundle.test.ts
@@ -73,6 +73,16 @@ describe('trimUrl', () => {
expect(trimUrl(url, 'origin')).toBe('https://app.example.com');
});
+ it('drops the query and fragment of an opaque-origin URL outside full mode', () => {
+ expect(trimUrl('file:///Users/jane/notes.html?q=secret#top', 'path')).toBe('file:///Users/jane/notes.html');
+ expect(trimUrl('file:///Users/jane/notes.html?q=secret', 'origin')).toBe('file://');
+ });
+
+ it('never ships the payload of a data URL outside full mode', () => {
+ expect(trimUrl('data:text/html,<p>[email protected]</p>', 'path')).toBe('data:');
+ expect(trimUrl('data:text/html,<p>[email protected]</p>', 'origin')).toBe('data:');
+ });
+
it('discards a URL it cannot parse rather than passing it through', () => {
expect(trimUrl('not a url', 'path')).toBe('');
});
@@ -164,6 +174,36 @@ describe('exportGuideAsBundle', () => {
expect(step.screenshotId).toBeUndefined();
});
+ it('never ships what narration heard, whatever the typed-text option', async () => {
+ const step = makeStep({ narratedDescription: 'my password is hunter3', description: 'Type the password' });
+ for (const stripInputValues of [true, false]) {
+ const { entries } = await unpack(
+ await exportGuideAsBundle(makeGuide(), [step], new Map([['step-1', makeScreenshot()]]), {
+ ...DEFAULT_BUNDLE_OPTIONS,
+ stripInputValues,
+ }),
+ );
+
+ expect(strFromU8(entries[MANIFEST_PATH])).not.toContain('hunter3');
+ }
+ });
+
+ it('scrubs a typed value out of a full URL, encoded or not', async () => {
+ const step = makeStep({
+ inputValue: 'jane [email protected]',
+ description: 'Search',
+ url: 'https://app.example.com/search?q=jane+doe%40corp.com&raw=jane [email protected]',
+ });
+ const { manifest } = await unpack(
+ await exportGuideAsBundle(makeGuide(), [step], new Map([['step-1', makeScreenshot()]]), {
+ ...DEFAULT_BUNDLE_OPTIONS,
+ urls: 'full',
+ }),
+ );
+
+ expect(manifest.steps[0].url).not.toContain('jane');
+ });
+
it('trims the href inside elementMeta too', async () => {
const step = makeStep({
elementMeta: {
diff --git a/src/core/transfer/__tests__/scrub.test.ts b/src/core/transfer/__tests__/scrub.test.ts
index 4cc68e1..c05ea5e 100644
--- a/src/core/transfer/__tests__/scrub.test.ts
+++ b/src/core/transfer/__tests__/scrub.test.ts
@@ -1,5 +1,5 @@
import { describe, expect, it } from 'vitest';
-import { MIN_BARE_SCRUB, SCRUB_PLACEHOLDER, scrubValues, typedValues } from '../scrub';
+import { MIN_BARE_SCRUB, SCRUB_PLACEHOLDER, scrubUrl, scrubValues, typedValues } from '../scrub';
describe('scrubValues', () => {
it('removes the value from the description the capture pipeline writes', () => {
@@ -67,3 +67,48 @@ describe('typedValues', () => {
).toEqual(['a much longer value', 'short']);
});
});
+
+describe('scrubUrl', () => {
+ it('never touches the scheme or host, even when a typed value matches them', () => {
+ expect(scrubUrl('https://github.com/search?q=github', ['github'])).toBe(
+ `https://github.com/search?q=${encodeURIComponent(SCRUB_PLACEHOLDER)}`,
+ );
+ });
+
+ it('finds a value the browser form-encoded', () => {
+ const url = scrubUrl('https://a.example/s?q=%28555%29+123-4567&page=2', ['(555) 123-4567']);
+ expect(url).toBe(`https://a.example/s?q=${encodeURIComponent(SCRUB_PLACEHOLDER)}&page=2`);
+ });
+
+ it('removes a short value that is a whole query value', () => {
+ expect(scrubUrl('https://a.example/check?pin=123', ['123'])).toBe(
+ `https://a.example/check?pin=${encodeURIComponent(SCRUB_PLACEHOLDER)}`,
+ );
+ });
+
+ it('removes a value from a path segment and the fragment', () => {
+ const url = scrubUrl('https://a.example/users/jane%40corp.com#[email protected]', ['[email protected]']);
+ expect(url).not.toContain('jane');
+ expect(url.startsWith('https://a.example/users/')).toBe(true);
+ });
+
+ it('returns the URL untouched when nothing in it was typed', () => {
+ const url = 'https://a.example/a%20b?x=1+2';
+ expect(scrubUrl(url, ['hunter2'])).toBe(url);
+ });
+
+ it('does not throw on a value cut through the middle of an emoji', () => {
+ const cut = `${'a'.repeat(79)}πŸ˜€`.slice(0, 80);
+ expect(() => scrubUrl('https://a.example/?q=x', [cut])).not.toThrow();
+ });
+
+ it('keeps the shape of a URL that ends in a bare ? or #', () => {
+ const placeholder = encodeURIComponent(SCRUB_PLACEHOLDER);
+ expect(scrubUrl('https://a.example/users/hunter22?', ['hunter22'])).toBe(`https://a.example/users/${placeholder}`);
+ expect(scrubUrl('https://a.example/users/hunter22#', ['hunter22'])).toBe(`https://a.example/users/${placeholder}`);
+ });
+
+ it('scrubs an opaque URL as plain text, since it has no host to protect', () => {
+ expect(scrubUrl('data:text/plain,hunter22', ['hunter22'])).toBe(`data:text/plain,${SCRUB_PLACEHOLDER}`);
+ });
+});
diff --git a/src/core/transfer/bundle.ts b/src/core/transfer/bundle.ts
index 018a1a8..74ba45d 100644
--- a/src/core/transfer/bundle.ts
+++ b/src/core/transfer/bundle.ts
@@ -12,7 +12,7 @@ import {
README_PATH,
SCREENSHOT_DIR,
} from './schema';
-import { scrubValues, typedValues } from './scrub';
+import { scrubUrl, scrubValues, typedValues } from './scrub';
export type BundleUrlMode = 'full' | 'path' | 'origin';
@@ -34,13 +34,27 @@ export function trimUrl(url: string, mode: BundleUrlMode): string {
} catch {
return '';
}
- if (parsed.origin === 'null') return url;
+ if (parsed.origin === 'null') {
+ if (parsed.protocol === 'data:') return 'data:';
+ if (mode === 'origin' && parsed.protocol === 'file:') return 'file://';
+ return url.split(/[?#]/)[0];
+ }
return mode === 'origin' ? parsed.origin : `${parsed.origin}${parsed.pathname}`;
}
function bundleStep(step: Step, options: BundleOptions, secrets: readonly string[]): BundleStep {
- const { guideId: _guideId, aiPending: _aiPending, screenshotId: _screenshotId, ...rest } = step;
- const travelling: BundleStep = { ...rest, url: trimUrl(step.url, options.urls) };
+ const {
+ guideId: _guideId,
+ aiPending: _aiPending,
+ screenshotId: _screenshotId,
+ narratedDescription: _narratedDescription,
+ ...rest
+ } = step;
+ const shareUrl = (url: string) => {
+ const trimmed = trimUrl(url, options.urls);
+ return options.stripInputValues ? scrubUrl(trimmed, secrets) : trimmed;
+ };
+ const travelling: BundleStep = { ...rest, url: shareUrl(step.url) };
if (options.stripInputValues) {
delete travelling.inputValue;
@@ -52,7 +66,7 @@ function bundleStep(step: Step, options: BundleOptions, secrets: readonly string
const ownText = options.stripInputValues && step.inputValue ? null : meta.textContent;
travelling.elementMeta = {
...meta,
- href: meta.href ? trimUrl(meta.href, options.urls) : null,
+ href: meta.href ? shareUrl(meta.href) : null,
textContent: ownText && options.stripInputValues ? scrubValues(ownText, secrets) : ownText,
};
}
diff --git a/src/core/transfer/schema.ts b/src/core/transfer/schema.ts
index b8eca8f..8d8c2da 100644
--- a/src/core/transfer/schema.ts
+++ b/src/core/transfer/schema.ts
@@ -17,7 +17,7 @@ export const MANIFEST_PATH = 'manifest.json';
export const SCREENSHOT_DIR = 'screenshots';
export const README_PATH = 'README.md';
-export type BundleStep = Omit<Step, 'guideId' | 'aiPending' | 'screenshotId'>;
+export type BundleStep = Omit<Step, 'guideId' | 'aiPending' | 'screenshotId' | 'narratedDescription'>;
export interface BundleScreenshot {
id: string;
diff --git a/src/core/transfer/scrub.ts b/src/core/transfer/scrub.ts
index 410c798..53f7bda 100644
--- a/src/core/transfer/scrub.ts
+++ b/src/core/transfer/scrub.ts
@@ -23,6 +23,60 @@ export function scrubValues(text: string, values: readonly string[]): string {
return out;
}
+function decodePart(raw: string, plusIsSpace: boolean): string | null {
+ try {
+ return decodeURIComponent(plusIsSpace ? raw.replace(/\+/g, ' ') : raw);
+ } catch {
+ return null;
+ }
+}
+
+function scrubPart(raw: string, values: readonly string[], plusIsSpace: boolean): string {
+ const decoded = decodePart(raw, plusIsSpace);
+ if (decoded === null) return raw;
+ const exact = values.some((value) => value.trim() !== '' && decoded === value.trim());
+ const scrubbed = exact ? SCRUB_PLACEHOLDER : scrubValues(decoded, values);
+ return scrubbed === decoded ? raw : encodeURIComponent(scrubbed);
+}
+
+function scrubQuery(search: string, values: readonly string[]): string {
+ if (search.length <= 1) return search;
+ const pairs = search
+ .slice(1)
+ .split('&')
+ .map((pair) => {
+ const at = pair.indexOf('=');
+ if (at === -1) return scrubPart(pair, values, true);
+ return `${pair.slice(0, at)}=${scrubPart(pair.slice(at + 1), values, true)}`;
+ });
+ return `?${pairs.join('&')}`;
+}
+
+export function scrubUrl(url: string, values: readonly string[]): string {
+ if (!url || values.length === 0) return url;
+ let parsed: URL;
+ try {
+ parsed = new URL(url);
+ } catch {
+ return scrubValues(url, values);
+ }
+ if (parsed.origin === 'null' && parsed.protocol !== 'file:') return scrubValues(url, values);
+
+ const pathname = parsed.pathname
+ .split('/')
+ .map((segment) => scrubPart(segment, values, false))
+ .join('/');
+ const search = scrubQuery(parsed.search, values);
+ const hash = parsed.hash ? `#${scrubPart(parsed.hash.slice(1), values, false)}` : '';
+ if (pathname === parsed.pathname && search === parsed.search && hash === parsed.hash) return url;
+
+ const next = new URL(parsed.href);
+ next.pathname = pathname;
+ next.search = search;
+ next.hash = hash;
+ return next.href;
+}
+
const CAPTURED_TEXT_LIMIT = 80;
function variantsOf(value: string): string[] {