Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,22 @@ See [STATUS.md](server/STATUS.md) to learn more about which features will remain

## UNRELEASED

- State-changing endpoints require a version 2 request signature, and accept
each one once (#1700, piece 6 and answer 7). `POST`/`DELETE` on
`/app-agent`, `/app-write`, `/plugin-view-token`, `/plugin-secret`,
`/plugin-run`, `/plugin-schedule`, `/plugin-resume`, `/plugin-auto-apply`,
`/plugin-trigger`, the `/plugin-release*`, `/plugin-sync-*`,
`/plugin-connection-*` and `/plugin-external-*` routes, the 13
`/integration-action*` routes, `/bind-drive`, `/forget-peer`, `/iroh-sync`
and the `/website-hosting` writes refuse version 1 signatures, bearer
tokens and session cookies with a `401`. A middleware reads the body before
the handler, checks the signature over exactly those bytes, and hands them
on. An in-memory replay cache per node remembers every accepted v2
signature (by the SHA-256 of its bytes) until it can no longer be fresh,
and refuses a second use; it holds at most 100,000 and answers `429` when
full rather than forget a live one. `GET` on the same paths still takes
version 1. `/commit`, `PUT /blob`, `/upload` and `POST` on other resources
are unchanged. See docs/src/authentication.md.
- wasip2 class extenders do not reach the integration proxy (#1700, answer
5). They were already refused, because the host has no installation agent
to sign as for them; the refusal now comes first, whether the extender uses
Expand Down
16 changes: 16 additions & 0 deletions TESTING_COVERAGE.md
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,22 @@ A wasip2 class extender is refused at the integration proxy, by URL and by
`atomic-proxy:`, even when its manifest lists the proxy origin (#1700, answer
5): `host_core::tests::a_class_extender_is_refused_at_the_proxy_and_told_why`.

Version 2 required on state-changing endpoints, with replay protection
(#1700, piece 6 and answer 7): `app_endpoints_test::state_changing_routes_refuse_v1_and_cookies_and_accept_v2`
sends every route on the list (including all 13 `/integration-action*`
routes and the `DELETE`s) a v1 signature, a session cookie and a v2
signature through the real router and middleware; `a_replayed_v2_request_is_refused`
replays a captured v2 request byte for byte; `reads_on_v2_routes_still_accept_v1`
covers `GET`. `replay_cache::tests` cover the window edges, a proof signed
ahead of the server clock, and a full cache. `server/tests/it/iroh_pairing.rs`
posts `/iroh-sync` with v2 between two real servers. The browser callers are
covered with mocked signing (`plugin-server`, `plugin-install`,
`plugin-connection`, `integration-actions`, `hostingClient`, `hostStore`,
`managedServer`, `pairing`), and `authentication-v2.test.ts` verifies what
`signedRequestInit` produces. Not covered: a real browser against a real
server for these writes (the Playwright suite exercises some of them
end-to-end), and a restart forgetting the cache.

Issues view: `TablePage/Issues/issueStatus.test.ts` covers reading open/closed
status tags and booleans, picking close/reopen targets, and title/`#number`
filtering; `browser/e2e/tests/issues-view.spec.ts` covers the Issues view for
Expand Down
1 change: 1 addition & 0 deletions browser/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ This changelog covers all five packages, as they are (for now) updated as a whol

## UNRELEASED

- `@tomic/lib`: `signedRequestInit(url, agent, { method, body, headers })` returns the `fetch` options for a version 2 signed request, over exactly the body it sends. AtomicServer now requires version 2 on its state-changing endpoints and accepts each signature once (#1700), so the data browser and `@tomic/lib` sign every write to them with it: `/app-agent`, `/app-write`, `/plugin-view-token`, `/plugin-secret`, `/plugin-run`, `/plugin-schedule`, `/plugin-resume`, `/plugin-auto-apply`, `/plugin-trigger`, `/plugin-release*`, `/plugin-sync-*`, `/plugin-connection-*`, `/plugin-external-*`, `/integration-action*`, `/forget-peer`, `/iroh-sync` and the `/website-hosting` writes. Reads on those paths still sign version 1.
- `@tomic/lib`: `signRequest(url, agent, headers, { method, body })` makes a version 2 request signature (ontola/atomic-plugins#54), which also covers the method and the SHA-256 of the body and sends `x-atomic-signature-version: 2`. Without `method` it signs version 1 as before, and a string fourth argument is still the legacy subject. New exports `requestSignatureMessageV2`, `sha256Hex` and `SIGNATURE_VERSION_HEADER`. `Agent.generateNonExtractable()` makes an agent whose Ed25519 key is a non-extractable WebCrypto key, with subject `atomic:agent:<public key>`; where WebCrypto has no Ed25519 it throws instead of falling back to an extractable key.
- Plugins moved to [atomic-plugins](https://github.com/ontola/atomic-plugins). The Integrations page lists what that catalog publishes (`catalog.json`, fetched at runtime; the URL is configurable under Settings > Integration) instead of plugins compiled into the app and server. The bundled GitHub issues, Notion, Pets, MT940/camt.053, Clockify and Google Calendar (Devonian) integrations, the `devonian` dependency and the `/app/devonian-demo` page are removed. The Todoist lens and the Moneybird administration picker are removed too. LocalThought connect and sync, and the "Show API plugins" toggle, are removed from the app: plugins will run in their own iframe and make proxy calls through the host.
- Tracker tables get an Issues view: open and closed issues split by the status column (or a boolean column), filtering by title or `#number`, New issue, and Close/Reopen per row. The Issue Tracker template opens it as a tab.
Expand Down
20 changes: 13 additions & 7 deletions browser/data-browser/src/chunks/AppPage/AppFrame.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@ import { isViewRequest } from '@tomic/plugin';
import { viewSession } from '@helpers/extensions/viewSession';
import { useEffect, useRef, useState } from 'react';
import { styled } from 'styled-components';
import { errorMessageFromResponse, signRequest, useStore } from '@tomic/react';
import {
errorMessageFromResponse,
signedRequestInit,
useStore,
} from '@tomic/react';
import { findSchema, pluginSchema } from '@tomic/lib';
import { FrameBridge } from '@helpers/extensions/FrameBridge';
import { handleRequest, isHostRequest, type HostReply } from './hostStore';
Expand Down Expand Up @@ -455,12 +459,14 @@ async function mintViewToken(
const url = `${store.getServerUrl()}/plugin-view-token`;

try {
const headers = await signRequest(url, agent, {});
const response = await fetch(url, {
method: 'POST',
headers: { ...headers, 'Content-Type': 'application/json' },
body: JSON.stringify({ drive, plugin }),
});
const response = await fetch(
url,
await signedRequestInit(url, agent, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ drive, plugin }),
}),
);

if (!response.ok) {
return {
Expand Down
23 changes: 12 additions & 11 deletions browser/data-browser/src/chunks/AppPage/appAgent.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {
errorMessageFromResponse,
signRequest,
signedRequestInit,
type Store,
} from '@tomic/react';

Expand All @@ -25,17 +25,18 @@ export async function handOverAppKey(
if (!agent) throw new Error('Sign in to give an app its key');

const url = `${store.getServerUrl()}/app-agent`;
const headers = await signRequest(url, agent, {});

const response = await fetch(url, {
method: 'POST',
headers: { ...headers, 'Content-Type': 'application/json' },
body: JSON.stringify({
drive: options.drive,
app: options.app,
secret: options.secret,
const response = await fetch(
url,
await signedRequestInit(url, agent, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
drive: options.drive,
app: options.app,
secret: options.secret,
}),
}),
});
);

if (!response.ok) {
throw new Error(
Expand Down
14 changes: 13 additions & 1 deletion browser/data-browser/src/chunks/AppPage/hostStore.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,19 @@ vi.mock('@tomic/react', async () => {

// Signing needs a real key and a real agent; what these tests are about is
// which requests leave and which are refused before they do.
return { ...actual, signRequest: async () => ({}) };
return {
...actual,
signRequest: async () => ({}),
signedRequestInit: async (
_url: string,
_agent: unknown,
request: { method: string; headers?: object; body?: string },
) => ({
method: request.method,
headers: { ...request.headers },
body: request.body,
}),
};
});

const APP = 'did:ad:app';
Expand Down
17 changes: 9 additions & 8 deletions browser/data-browser/src/chunks/AppPage/hostStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
errorMessageFromResponse,
findSchema,
pluginSchema,
signRequest,
signedRequestInit,
} from '@tomic/react';

/**
Expand Down Expand Up @@ -243,13 +243,14 @@ async function writeAsApp(
if (!agent) throw new Error('Sign in to use this app');

const url = `${store.getServerUrl()}/app-write`;
const headers = await signRequest(url, agent, {});

const response = await fetch(url, {
method: 'POST',
headers: { ...headers, 'Content-Type': 'application/json' },
body: JSON.stringify({ drive, app, ...request }),
});
const response = await fetch(
url,
await signedRequestInit(url, agent, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ drive, app, ...request }),
}),
);

if (!response.ok) {
throw new Error(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useState } from 'react';
import {
dataBrowser,
signRequest,
signedRequestInit,
useStore,
ensureSchema,
pluginSchema,
Expand Down Expand Up @@ -66,21 +66,21 @@ export function CreateEventAutomation({
await script.set(dataBrowser.properties.emoji, '⚡');
await script.save();
const url = `${store.getServerUrl()}/plugin-trigger`;
const response = await fetch(url, {
method: 'POST',
headers: {
...(await signRequest(url, store.getAgent()!, {})),
'Content-Type': 'application/json',
},
body: JSON.stringify({
drive,
plugin: subject,
filters: selected.filters,
onEnter: true,
onLeave: false,
autoApply: false,
const response = await fetch(
url,
await signedRequestInit(url, store.getAgent()!, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
drive,
plugin: subject,
filters: selected.filters,
onEnter: true,
onLeave: false,
autoApply: false,
}),
}),
});
);
if (!response.ok) throw new Error(await response.text());
navigate(constructOpenURL(subject));
if (withAssistant)
Expand Down
31 changes: 25 additions & 6 deletions browser/data-browser/src/chunks/PluginRuns/PluginSchedule.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@ import { useCallback, useEffect, useState } from 'react';
import { styled } from 'styled-components';
import toast from 'react-hot-toast';
import { FaClock } from 'react-icons/fa6';
import { errorMessageFromResponse, signRequest, useStore } from '@tomic/react';
import {
errorMessageFromResponse,
signedRequestInit,
signRequest,
useStore,
} from '@tomic/react';
import { setPluginSchedule } from './runScript';
import { Button } from '@components/Button';
import { Column, Row } from '@components/Row';
Expand Down Expand Up @@ -276,11 +281,25 @@ async function request(
if (!agent) return { ok: false, error: 'Not signed in' };

try {
const headers = await signRequest(url, agent, {});
const response = await fetch(url, {
...init,
headers: { ...headers, 'Content-Type': 'application/json' },
});
const method = (init.method ?? 'GET').toUpperCase();
// Reads sign with version 1; every write is a v2-only route, signed over
// the method, URL and exactly this body.
const response = await fetch(
url,
method === 'GET'
? {
...init,
headers: {
...(await signRequest(url, agent, {})),
'Content-Type': 'application/json',
},
}
: await signedRequestInit(url, agent, {
method,
headers: { 'Content-Type': 'application/json' },
body: init.body as string | undefined,
}),
);

if (!response.ok) {
return {
Expand Down
25 changes: 20 additions & 5 deletions browser/data-browser/src/chunks/PluginRuns/PluginSecrets.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import toast from 'react-hot-toast';
import { FaCheck, FaKey, FaTrash } from 'react-icons/fa6';
import {
errorMessageFromResponse,
signedRequestInit,
signRequest,
useStore,
type DeclaredSecret,
Expand Down Expand Up @@ -422,11 +423,25 @@ async function request(
if (!agent) return { ok: false, error: 'Not signed in' };

try {
const headers = await signRequest(url, agent, {});
const response = await fetch(url, {
...init,
headers: { ...headers, 'Content-Type': 'application/json' },
});
const method = (init.method ?? 'GET').toUpperCase();
// Reads sign with version 1; every write is a v2-only route, signed over
// the method, URL and exactly this body.
const response = await fetch(
url,
method === 'GET'
? {
...init,
headers: {
...(await signRequest(url, agent, {})),
'Content-Type': 'application/json',
},
}
: await signedRequestInit(url, agent, {
method,
headers: { 'Content-Type': 'application/json' },
body: init.body as string | undefined,
}),
);

if (!response.ok) {
return {
Expand Down
36 changes: 18 additions & 18 deletions browser/data-browser/src/chunks/PluginRuns/PluginTrigger.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useEffect, useState } from 'react';
import { signRequest, useStore } from '@tomic/react';
import { signedRequestInit, signRequest, useStore } from '@tomic/react';
import { Button } from '@components/Button';
import { Column, Row } from '@components/Row';
import { Card } from '@components/Card';
Expand Down Expand Up @@ -59,24 +59,24 @@ export function PluginTrigger({
setError(undefined);

try {
const response = await fetch(endpoint, {
method: 'POST',
headers: {
...(await signRequest(endpoint, store.getAgent()!, {})),
'Content-Type': 'application/json',
},
body: JSON.stringify({
drive,
plugin,
filters: trigger.query.filters.map(f => ({
property: f.property,
value: f.value,
})),
onEnter: trigger.onEnter,
onLeave: trigger.onLeave,
autoApply: enabled,
const response = await fetch(
endpoint,
await signedRequestInit(endpoint, store.getAgent()!, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
drive,
plugin,
filters: trigger.query.filters.map(f => ({
property: f.property,
value: f.value,
})),
onEnter: trigger.onEnter,
onLeave: trigger.onLeave,
autoApply: enabled,
}),
}),
});
);
if (!response.ok) throw new Error(await response.text());
setTrigger(await response.json());
} catch (e) {
Expand Down
24 changes: 12 additions & 12 deletions browser/data-browser/src/chunks/PluginRuns/runScript.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import {
// only the entry file, leaving its relative imports missing in production.
import PluginWorker from '@tomic/lib/plugin-run.worker.js?worker';
import { useEffect, useState } from 'react';
import { signRequest } from '@tomic/react';
import { signedRequestInit, signRequest } from '@tomic/react';

/**
* Running a plugin and applying what it proposed are separate calls on purpose.
Expand Down Expand Up @@ -629,18 +629,18 @@ export async function setPluginSchedule(
if (!agent) throw new Error('Not signed in');

const url = `${store.getServerUrl()}/plugin-schedule`;
const response = await fetch(url, {
method: 'POST',
headers: {
...(await signRequest(url, agent, {})),
'Content-Type': 'application/json',
},
body: JSON.stringify({
drive: target.drive,
plugin: target.plugin,
intervalSeconds,
const response = await fetch(
url,
await signedRequestInit(url, agent, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
drive: target.drive,
plugin: target.plugin,
intervalSeconds,
}),
}),
});
);

if (!response.ok) {
throw new Error(
Expand Down
Loading
Loading