Skip to content

Commit a2265b7

Browse files
committed
Review fixes: legacy key screen cannot strand a vault; spend refusals skip the prompt queue; vault cost bounded
The legacy-key screen shows only when nothing else is set up, and an unencrypted copy is removed when the vault unlocks to that same key. Spend refusals come before the per-site prompt queue. scrypt parameters read from a vault are bounded. The release workflow holds write access only in its publishing job. Privacy and store text corrected. Co-Authored-By: jjohare <[email protected]>
1 parent 8114d3b commit a2265b7

11 files changed

Lines changed: 89 additions & 25 deletions

File tree

‎.github/workflows/release.yml‎

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ on:
88
- 'v*'
99

1010
permissions:
11-
contents: write
11+
contents: read
1212

1313
jobs:
14-
release:
14+
build:
1515
runs-on: ubuntu-latest
1616
steps:
1717
- name: Checkout
@@ -80,6 +80,28 @@ jobs:
8080
print(f'package holds all {len(set(need))} files the extension loads')
8181
PY
8282
83+
- name: Hand the zip to the publishing job
84+
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
85+
with:
86+
name: release
87+
path: |
88+
dist/podkey-${{ github.ref_name }}.zip
89+
dist/podkey-${{ github.ref_name }}.zip.sha256
90+
if-no-files-found: error
91+
92+
# Write access is held only here, by a job that runs no project code.
93+
publish:
94+
needs: build
95+
runs-on: ubuntu-latest
96+
permissions:
97+
contents: write
98+
steps:
99+
- name: Fetch the zip
100+
uses: actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093 # v4.3.0
101+
with:
102+
name: release
103+
path: dist
104+
83105
- name: Create the release
84106
uses: softprops/action-gh-release@3bb12739c298aeb8a4eeaf626c5b8d85266b0e65 # v2.6.2
85107
with:

‎PRIVACY.md‎

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,17 +45,19 @@ remote logging.** Podkey collects none of your browsing history or page content.
4545
Closing the prompt, or a 60-second timeout, denies it.
4646
- Apart from the opt-in sidechain feature below, Podkey makes **no network
4747
requests of its own.** A NIP-98 `Authorization` header is attached only to
48-
requests **you** initiate to a Solid/Nostr server you have trusted; the data
49-
goes to that server, under your control, not to Podkey.
48+
requests made by a site you have approved, to a server you have trusted or
49+
to one of the well-known Solid hosts (`solidcommunity.net`, `solid.social`,
50+
`inrupt.net`, `solidweb.org`), and only with auto-sign turned on; the data
51+
goes to that server, not to Podkey.
5052
- The key is locked automatically after 30 minutes without use, and when the
51-
screen locks, and exporting it needs your passphrase again. You can also turn
53+
screen locks, and exporting it needs your passphrase again (or your passkey,
54+
if the key is derived from one). You can also turn
5255
Podkey off for a single site from the popup.
5356

5457
## Sidechain spends (opt-in)
5558

5659
Sidechain spends are **off by default**. A site can ask you to approve a
57-
sidechain spend only after you turn them on, in the popup's settings or from the
58-
spend window. While they are off, none of what follows happens.
60+
sidechain spend only after you turn them on in the popup's settings. While they are off, none of what follows happens.
5961

6062
When you review a spend, Podkey looks up the chain it belongs to. That is the
6163
only time it opens connections of its own:

‎popup/popup.js‎

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -193,13 +193,15 @@ async function checkKeypairStatus () {
193193
const response = await chrome.runtime.sendMessage({ type: 'GET_KEYPAIR_STATUS' });
194194
if (DEBUG) console.log('[Podkey Popup] Keypair status response:', response);
195195

196-
// A key an older Podkey left unencrypted comes first: whatever else is
197-
// true, the person has to export or seal it before it is lost or left on disk.
198-
if (response.legacyPlaintextKey) {
196+
const state = response.state || (response.exists ? 'unlocked' : 'none');
197+
// A key an older Podkey left unencrypted, and nothing else: the person has
198+
// to export or seal it before it is lost or left on disk. Where a vault or
199+
// passkey identity exists the screen is not shown, because its only way out
200+
// deletes those too.
201+
if (response.legacyPlaintextKey && state === 'none') {
199202
showLegacyScreen(response);
200203
return;
201204
}
202-
const state = response.state || (response.exists ? 'unlocked' : 'none');
203205
if (state === 'unlocked') {
204206
await showMainScreen(response);
205207
} else if (state === 'locked') {

‎site/privacy.html‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,12 +75,12 @@ <h2>How your key is used</h2>
7575
<ul>
7676
<li>Signing (NIP-07), NIP-44 encryption, and Solid authentication (NIP-98) happen entirely inside the extension's background service worker. The raw private key is never exposed to web pages: the page receives only the resulting signature, ciphertext/plaintext, or <code>Authorization</code> header.</li>
7777
<li>A site you have not approved triggers a consent prompt on its first request; closing it, or a 60-second timeout, denies it.</li>
78-
<li>Apart from the opt-in sidechain feature below, Podkey makes <strong>no network requests of its own</strong>. A NIP-98 <code>Authorization</code> header is attached only to requests <em>you</em> initiate to a server you have trusted; the data goes to that server, under your control, not to Podkey.</li>
79-
<li>The key locks automatically after 30 minutes without use and when the screen locks, and exporting it needs your passphrase again. You can also turn Podkey off for a single site from the popup.</li>
78+
<li>Apart from the opt-in sidechain feature below, Podkey makes <strong>no network requests of its own</strong>. A NIP-98 <code>Authorization</code> header is attached only to requests made by a site you have approved, to a server you have trusted or to one of the well-known Solid hosts (<code>solidcommunity.net</code>, <code>solid.social</code>, <code>inrupt.net</code>, <code>solidweb.org</code>), and only with auto-sign turned on; the data goes to that server, not to Podkey.</li>
79+
<li>The key locks automatically after 30 minutes without use and when the screen locks, and exporting it needs your passphrase again (or your passkey, if the key is derived from one). You can also turn Podkey off for a single site from the popup.</li>
8080
</ul>
8181

8282
<h2 id="sidechain">Sidechain spends (opt-in)</h2>
83-
<p>Sidechain spends are <strong>off by default</strong>. A site can ask you to approve one only after you turn them on, in the popup's settings or from the spend window. While they are off, none of this happens.</p>
83+
<p>Sidechain spends are <strong>off by default</strong>. A site can ask you to approve one only after you turn them on in the popup's settings. While they are off, none of this happens.</p>
8484
<p>When you review a spend, Podkey looks up the chain it belongs to. That is the only time it opens connections of its own:</p>
8585
<ul>
8686
<li><strong>Public Nostr relays.</strong> The spend window opens WebSocket connections to <code>wss://nos.lol</code>, <code>wss://relay.damus.io</code>, <code>wss://relay.primal.net</code>, <code>wss://nostr.mom</code> and <code>wss://nostr.oxtr.dev</code> and asks each for the chain's latest signed announcement (a Nostr event of kind 33333 tagged with the chain identifier), and for the profile names (kind 0 events) of the public keys the spend pays or involves, so the window can show a name instead of a bare key. Each relay learns your <strong>IP address</strong>, the <strong>chain identifier</strong> you are looking up, the <strong>public keys under review</strong>, and when.</li>

‎src/background.js‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,7 @@ async function handleMessage (message, sender) {
355355
return await handleNip44Decrypt(message.pubkey, message.ciphertext, origin);
356356

357357
case 'SIDESTR_SIGN_TRANSACTION':
358-
return await runExclusive(origin, () => spends.request({ chain: message.chain, tx: message.tx }, origin));
358+
return await spends.request({ chain: message.chain, tx: message.tx }, origin);
359359

360360
case 'SIDESTR_REQUEST':
361361
return spends.describe(message.id);
@@ -527,6 +527,7 @@ async function askConsent (origin, action, eventPreview, options) {
527527
* person confirms. See src/sidestr/spends.js.
528528
*/
529529
const spends = createSpends({
530+
exclusive: (origin, run) => runExclusive(origin, run),
530531
// A locked Podkey opens its unlock window only for a site the person trusts;
531532
// any other site is told to ask again once Podkey is unlocked.
532533
ensureUnlocked: async (origin) => {
@@ -860,6 +861,9 @@ async function handleUnlockVault (passphrase) {
860861
const privateKey = await unlockVault(passphrase); // throws on wrong passphrase
861862
const publicKey = getPublicKey(privateKey);
862863
await storeKeypair(privateKey, publicKey); // populate session cache
864+
// An unencrypted copy of the key this vault just gave up is spare. A
865+
// different key is never ours to delete: it waits to be exported or sealed.
866+
if ((await getLegacyPlaintextKey()) === privateKey) await removeLegacyPlaintextKey();
863867
armIdleTimer();
864868
await updateActionBadge();
865869
await pushPageStates();

‎src/sidestr/spends.js‎

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ export const SPEND_WINDOW_MS = 4 * 60 * 1000;
2525
/** At most this many inputs are signed in one request. */
2626
export const MAX_INPUTS = 500;
2727

28-
export function createSpends ({ storage = globalThis.chrome?.storage?.local, ensureUnlocked, getKeypair, signSighashes, openWindow, now = () => Date.now(), setTimer = setTimeout, clearTimer = clearTimeout, randomId = () => crypto.randomUUID() }) {
28+
export function createSpends ({ storage = globalThis.chrome?.storage?.local, ensureUnlocked, getKeypair, signSighashes, openWindow, exclusive = (origin, run) => run(), now = () => Date.now(), setTimer = setTimeout, clearTimer = clearTimeout, randomId = () => crypto.randomUUID() }) {
2929
const pending = new Map(); // id -> { origin, chain, tx, inputs, pub, windowId, signed, settle }
3030
const busy = new Set(); // origins with a spend in flight, reserved before the first await
3131

@@ -45,11 +45,14 @@ export function createSpends ({ storage = globalThis.chrome?.storage?.local, ens
4545
// fail closed: spends are off unless the settings say they are on
4646
const enabled = storage ? (await loadSettings(storage)).enabled : false;
4747
if (!enabled) throw new SpendError('unsupported', "Sidechain spends are turned off in Podkey. Turn them on under Sidechain spends in Podkey's settings, then ask again.");
48-
try { await ensureUnlocked(origin); } catch (e) { throw new SpendError('unavailable', e.message); }
49-
const keypair = await getKeypair();
50-
if (!keypair || !/^[0-9a-f]{64}$/.test(keypair.publicKey ?? '')) throw new SpendError('unavailable', 'No key in Podkey');
51-
const id = randomId();
52-
return await new Promise((resolve, reject) => {
48+
// The refusals above come at once; only a spend that will open a window
49+
// takes its turn among the site's other prompts.
50+
return await exclusive(origin, async () => {
51+
try { await ensureUnlocked(origin); } catch (e) { throw new SpendError('unavailable', e.message); }
52+
const keypair = await getKeypair();
53+
if (!keypair || !/^[0-9a-f]{64}$/.test(keypair.publicKey ?? '')) throw new SpendError('unavailable', 'No key in Podkey');
54+
const id = randomId();
55+
return await new Promise((resolve, reject) => {
5356
const entry = {
5457
origin, chain: req.chain, tx: req.tx, inputs, pub: keypair.publicKey, windowId: null, signed: false, opened: now(),
5558
settle: (o) => (o.error ? reject(o.error) : resolve(o.result))
@@ -58,6 +61,7 @@ export function createSpends ({ storage = globalThis.chrome?.storage?.local, ens
5861
pending.set(id, entry);
5962
Promise.resolve(openWindow(id)).then((windowId) => { if (pending.has(id)) entry.windowId = windowId ?? null; })
6063
.catch((e) => settle(id, { error: new SpendError('unavailable', `Could not open the spend window: ${e.message}`) }));
64+
});
6165
});
6266
} finally {
6367
busy.delete(origin);

‎src/vault.js‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,13 @@ export async function decryptPrivateKey (blob, passphrase) {
9191
throw new Error('Unrecognised vault format');
9292
}
9393

94-
const kdf = { N: blob.N, r: blob.r, p: blob.p, dkLen: 32 };
94+
// The cost is read from the blob, so bound it: a tampered blob must not be
95+
// able to ask for gigabytes of memory or minutes of work on every unlock.
96+
const { N, r, p } = blob;
97+
if (!Number.isInteger(N) || N < 2 || N > (1 << 18) || (N & (N - 1)) !== 0 || r !== 8 || p !== 1) {
98+
throw new Error('Unrecognised vault format');
99+
}
100+
const kdf = { N, r, p, dkLen: 32, maxmem: 2 ** 29 };
95101
const key = await aesKey(deriveKeyBytes(passphrase, hexToBytes(blob.salt), kdf), ['decrypt']);
96102

97103
let pt;

‎store/SUBMISSION.md‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,8 @@ when the browser closes.
6262
6363
Per-site consent:
6464
An untrusted site raises a consent prompt on its first request; closing it, or
65-
a 60-second timeout, denies it. Approving grants per-origin trust you can revoke
66-
at any time from the popup.
65+
a 60-second timeout, denies it. You can approve one request, or trust the site,
66+
which you can revoke at any time from the popup.
6767
6868
Private by design:
6969
No servers, no accounts, no analytics, and nothing is collected. Sidechain
@@ -102,7 +102,7 @@ only ever see a public key, a signature, a NIP-44 payload, or an auth header.
102102
> excluded from the registration and gets no script at all.
103103
104104
- **`idle`**
105-
> Detects that the screen has locked or the user has been idle, so the
105+
> Detects that the screen has locked, so the
106106
> decrypted key is cleared from memory and Podkey locks itself. Used for
107107
> nothing else; no page or browsing data is read.
108108

‎test/sidestr-spends.test.js‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,13 @@ describe('sidestr spends', () => {
134134
await assert.rejects(() => spends.request(REQ, 'https://x.example'), (e) => e.code === 'unsupported');
135135
});
136136

137+
it('refuses at once without taking a turn in the site\'s prompt queue', async () => {
138+
const turns = [];
139+
const spends = createSpends({ storage: null, exclusive: (origin, run) => { turns.push(origin); return run(); }, ensureUnlocked: async () => {}, getKeypair: async () => ({ publicKey: PUB }), signSighashes: () => [], openWindow: async () => 1 });
140+
await assert.rejects(spends.request(REQ, 'https://shop.test'), (e) => e.code === 'unsupported');
141+
assert.deepEqual(turns, []);
142+
});
143+
137144
it('allows one pending spend per origin, even for requests fired together', async () => {
138145
const h = harness();
139146
const first = h.spends.request(REQ, 'https://a.example');

‎test/vault.test.js‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,9 @@ test('rejects an unrecognised vault format', async () => {
7070
test('a vault sealed at the earlier N=2^16 still opens', async () => {
7171
const { readFileSync } = await import('node:fs');
7272
const old = JSON.parse(readFileSync(new URL('./fixtures/vault-scrypt-n16.json', import.meta.url), 'utf8'));
73+
for (const bad of [{ N: 1 << 20 }, { N: 3000 }, { r: 64 }, { p: 16 }, { N: '65536' }]) {
74+
await assert.rejects(decryptPrivateKey({ ...old, ...bad }, 'x'), /Unrecognised vault format/, JSON.stringify(bad));
75+
}
7376
assert.equal(old.N, 65536);
7477
assert.equal(await decryptPrivateKey(old, 'legacy passphrase 2^16'), PRIVKEY);
7578
await assert.rejects(decryptPrivateKey(old, 'not the passphrase'), /Incorrect passphrase/);

0 commit comments

Comments
 (0)