Encrypt credentials at rest; unify clipboard-link suggestions

Encrypt proxy / youtubePoToken / updateToken on disk via safeStorage (DPAPI on Windows), with a one-time launch migration for legacy plaintext. Decrypted before reaching callers/renderer; backup export still writes clear, as documented. Harden updater token handling to refuse cross-origin redirects on the authenticated REST check.

Extract the clipboard-link logic from DownloadBar into the shared useClipboardLink hook: add an optional filter (library skips single-video links), an offer() for external aerofetch:// / .url links, and a source field driving banner wording. Add looksLikeSingleVideo plus its unit tests.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
2026-06-29 10:15:59 -04:00
parent f167c02946
commit 5a9f2de390
8 changed files with 278 additions and 100 deletions
+75
View File
@@ -0,0 +1,75 @@
import { describe, it, expect } from 'vitest'
import { looksLikeUrl, looksLikeSingleVideo } from '../src/renderer/src/useClipboardLink'
describe('looksLikeUrl', () => {
it('accepts http(s) URLs', () => {
expect(looksLikeUrl('https://youtube.com/watch?v=abc')).toBe(true)
expect(looksLikeUrl('http://example.com')).toBe(true)
expect(looksLikeUrl('https://example.com/a/b?c=d#frag')).toBe(true)
})
it('is scheme-case-insensitive', () => {
expect(looksLikeUrl('HTTPS://example.com')).toBe(true)
expect(looksLikeUrl('HtTp://example.com')).toBe(true)
})
it('trims surrounding whitespace', () => {
expect(looksLikeUrl(' https://example.com\n')).toBe(true)
expect(looksLikeUrl('\t http://example.com \t')).toBe(true)
})
it('rejects non-http(s) schemes', () => {
expect(looksLikeUrl('ftp://example.com')).toBe(false)
expect(looksLikeUrl('file:///c:/x')).toBe(false)
expect(looksLikeUrl('magnet:?xt=urn:btih:abc')).toBe(false)
expect(looksLikeUrl('javascript:alert(1)')).toBe(false)
expect(looksLikeUrl('mailto:a@b.com')).toBe(false)
})
it('rejects bare domains and scheme-less text', () => {
expect(looksLikeUrl('www.example.com')).toBe(false)
expect(looksLikeUrl('example.com/watch')).toBe(false)
expect(looksLikeUrl('see http://example.com')).toBe(false) // must start with the scheme
})
it('rejects empty, whitespace, and malformed input', () => {
expect(looksLikeUrl('')).toBe(false)
expect(looksLikeUrl(' ')).toBe(false)
expect(looksLikeUrl('not a link')).toBe(false)
expect(looksLikeUrl('http://')).toBe(false) // passes the prefix test but is not a valid URL
})
})
describe('looksLikeSingleVideo', () => {
it('flags YouTube single-video URLs', () => {
expect(looksLikeSingleVideo('https://www.youtube.com/watch?v=dQw4w9WgXcQ')).toBe(true)
expect(looksLikeSingleVideo('https://youtube.com/watch?v=abc123')).toBe(true)
expect(looksLikeSingleVideo('https://m.youtube.com/watch?v=abc123')).toBe(true)
expect(looksLikeSingleVideo('https://music.youtube.com/watch?v=abc123')).toBe(true)
expect(looksLikeSingleVideo('https://youtu.be/dQw4w9WgXcQ')).toBe(true)
})
it('keeps anything with a playlist context (?list=)', () => {
// A video opened in a playlist → the user likely wants the whole playlist.
expect(looksLikeSingleVideo('https://www.youtube.com/watch?v=abc&list=PL123')).toBe(false)
expect(looksLikeSingleVideo('https://youtu.be/abc?list=PL123')).toBe(false)
})
it('keeps channels and playlists', () => {
expect(looksLikeSingleVideo('https://www.youtube.com/@SomeChannel')).toBe(false)
expect(looksLikeSingleVideo('https://www.youtube.com/channel/UC123')).toBe(false)
expect(looksLikeSingleVideo('https://www.youtube.com/c/SomeChannel')).toBe(false)
expect(looksLikeSingleVideo('https://www.youtube.com/playlist?list=PL123')).toBe(false)
})
it('does not flag single videos on other sites (conservative)', () => {
// We can't reliably classify arbitrary hosts, so never reject them.
expect(looksLikeSingleVideo('https://vimeo.com/123456789')).toBe(false)
expect(looksLikeSingleVideo('https://example.com/watch?v=abc')).toBe(false)
})
it('returns false for non-URLs', () => {
expect(looksLikeSingleVideo('not a url')).toBe(false)
expect(looksLikeSingleVideo('')).toBe(false)
})
})