Skip to content
Merged
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 .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
version: 2
updates:
- package-ecosystem: npm
directory: /
schedule:
interval: weekly
groups:
npm-dependencies:
patterns: ['*']
- package-ecosystem: github-actions
directory: /
schedule:
interval: weekly
groups:
github-actions:
patterns: ['*']
20 changes: 20 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: CI
on:
push:
branches: [main]
pull_request:
permissions:
contents: read
jobs:
check:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v7
- uses: actions/setup-node@v7
with:
node-version: '22'
cache: npm
- run: npm ci --ignore-scripts
- run: npm run check
- run: npm test
- run: npm audit --audit-level=moderate
15 changes: 14 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,26 @@ npm run dev
```

The loopback service listens on `http://127.0.0.1:4347`. Open that address and
drag its loader bookmarklet into Chromium's bookmarks bar. The bookmark attaches
drag its loader bookmarklet into Google Chrome's bookmarks bar. The bookmark attaches
the overlay to the current local page without modifying that page's source.
The overlay records the autosaved working notebook in `.data/notes.json`.
Notebook revision metadata, preferences and snapshots remain beside it in
`.data/notebook.json`, `.data/preferences.json` and `.data/snapshots.json`.
Derived visual receipts live in `.data/thumbnails.json`.

Before loading DevNotes on a page, add that page address under **Approved pages**
in the dashboard. Approval is exact to its scheme, hostname and port. Each loader
carries a local access token; save the current loader again after this security
update. Removing a site immediately revokes its browser access.

The token and approved origins stay in owner-readable `.data/access.json`, beside
the private notebook. Keep loader bookmarks private. Approved sites with the
loader can access the notebook; only the dashboard or an authenticated local
client can change approvals. Command-line clients send `Authorization: Bearer`
with the token from that local file. Thumbnail capture checks approved HTTP(S)
origins and uses the same authentication. `ANNOTATION_DATA_DIR` relocates both
notebook data and access settings together.

The annotation ledger is intentionally ignored by Git. `.data/.gitkeep`
preserves the directory without publishing private note content.

Expand Down
56 changes: 56 additions & 0 deletions lib/access.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import { randomBytes, timingSafeEqual } from 'node:crypto';
import { chmod, readFile, writeFile } from 'node:fs/promises';
import { join } from 'node:path';

export function pageOrigin(value) {
try {
const url = new URL(value);
if (!['http:', 'https:'].includes(url.protocol) || url.username || url.password) return null;
return url.origin;
} catch { return null; }
}

export async function loadAccess(directory, port) {
const path = join(directory, 'access.json');
try {
await writeFile(path, `${JSON.stringify({ token: randomBytes(32).toString('hex'), origins: [] })}\n`, { flag: 'wx', mode: 0o600 });
} catch (error) {
if (error.code !== 'EEXIST') throw error;
}
await chmod(path, 0o600);
const settings = JSON.parse(await readFile(path, 'utf8'));
if (!/^[a-f0-9]{64}$/.test(settings.token) || !Array.isArray(settings.origins)
|| settings.origins.some((value) => pageOrigin(value) !== value)) {
throw new Error('Invalid local access settings. Restore access.json from a trusted backup.');
}
const local = new Set([`http://127.0.0.1:${port}`, `http://localhost:${port}`]);
const hosts = new Set([...local].map((value) => new URL(value).host));
const origins = new Set(settings.origins);
const token = settings.token;
return {
token,
origins: () => [...origins],
validHost: (request) => hosts.has(request.headers.host),
localRequest: (request) => !request.headers.origin || local.has(request.headers.origin),
allowedOrigin: (origin) => !origin || local.has(origin) || origins.has(origin),
authenticated(request) {
const value = request.headers.authorization || '';
const expected = `Bearer ${token}`;
return Buffer.byteLength(value) === Buffer.byteLength(expected)
&& timingSafeEqual(Buffer.from(value), Buffer.from(expected));
},
async update(origin, allow) {
const next = new Set(origins);
if (allow) next.add(origin); else next.delete(origin);
await writeFile(path, `${JSON.stringify({ token, origins: [...next] }, null, 2)}\n`, { mode: 0o600 });
origins.clear();
for (const item of next) origins.add(item);
},
};
}

export function captureUrl(value, origins) {
const origin = pageOrigin(value);
if (!origin || !origins.includes(origin)) throw new Error('Page is not approved for capture.');
return new URL(value).href;
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"type": "module",
"scripts": {
"dev": "node server.mjs",
"check": "node --check server.mjs && node --check public/client.js && node --check public/beta3.js",
"check": "node --check server.mjs && node --check public/client.js && node --check public/beta3.js && node --check lib/access.mjs && node --check scripts/capture-thumbnails.mjs",
"thumbnails": "node scripts/capture-thumbnails.mjs",
"verify:client": "node scripts/verify-client.mjs",
"verify:beta3": "node scripts/verify-beta3.mjs",
Expand Down
Loading