Changeset 679924e in Klonkt


Ignore:
Timestamp:
08/02/2026 08:06:21 AM (5 weeks ago)
Author:
Bart <bart@…>
Branches:
main
Children:
af035e6
Parents:
26c5f71
Message:

WebFinger: de primaire site via de ene bron van waarheid

Een verse instance heeft geen primaire site: is_primary is 0 by default en de
backfill draait alleen op het moment dat de kolom erbij komt. Een site die
daarna wordt aangemaakt laat de instance dus zonder vlag achter.

De HTML-kant merkte daar niets van, want getPrimarySite() valt terug op de
oudste site. Deze route hield zijn eigen is_primary-only kopie aan, precies het
verspreide gedrag dat middleware/site.js zegt te hebben opgeruimd. Dus / gaf de
site en WebFinger gaf 404, uit dezelfde database, in hetzelfde verzoek.

Gevonden op instance loop (🩵.is.wildenvrij.nl): één site, slug "mee",
is_primary 0. De andere instances kunnen in dezelfde staat staan.

De nieuwe test zet alle vlaggen op 0 en eist dat een kale host dan nog steeds
de oudste site vindt.

Co-Authored-By: Claude Opus 5 <claude@…>

Files:
2 edited

Legend:

Unmodified
Added
Removed
  • src/routes/activitypub.js

    r26c5f71 r679924e  
    2020import OAuth from '../services/OAuthService.js';
    2121import * as Guardianship from '../services/guardianship/index.js';
     22import { getPrimarySite } from '../middleware/site.js';
    2223import multer from 'multer';
    2324import path from 'path';
     
    4344const hostOf = (req) => { try { return new URL(baseUrl(req)).host; } catch { return req.get('host'); } };
    4445const publicSite = (slug) => db.prepare('SELECT * FROM sites WHERE slug = ? AND (is_public IS NULL OR is_public = 1)').get(slug);
    45 const primarySlug = () => { const r = db.prepare('SELECT slug FROM sites WHERE is_primary = 1').get(); return r && r.slug; };
     46// The primary site, via the one source of truth in middleware/site.js — which
     47// falls back to the oldest site when nothing carries the is_primary flag. This
     48// route used to keep its own is_primary-only copy, so a fresh instance whose
     49// site was never flagged served its HTML at / (that resolver falls back) while
     50// WebFinger and the actor route insisted it had no primary at all.
     51const primarySlug = () => { const s = getPrimarySite(); return s && s.slug; };
    4652// A hostname as a human types it and as DNS stores it are the same host:
    4753// `🩵.is.wildenvrij.nl` IS `xn--zz9h.is.wildenvrij.nl`. WHATWG URL does the IDNA,
  • test/webfinger-bare-host.test.js

    r26c5f71 r679924e  
    2828// `kid` is the primary site; `oma` is a second public site that must NOT be
    2929// what a bare host resolves to.
    30 db.prepare('INSERT INTO sites (id, slug, title, owner_id, is_primary) VALUES (?,?,?,?,1)').run('s1', 'kid', 'kid', 'u1');
    31 db.prepare('INSERT INTO sites (id, slug, title, owner_id, is_primary) VALUES (?,?,?,?,0)').run('s2', 'oma', 'oma', 'u1');
     30// Explicit created_at: getPrimarySite() falls back to the OLDEST site, and two
     31// rows inserted in the same second would make that order a coin flip.
     32db.prepare('INSERT INTO sites (id, slug, title, owner_id, is_primary, created_at) VALUES (?,?,?,?,1,?)')
     33  .run('s1', 'kid', 'kid', 'u1', '2026-01-01 00:00:00');
     34db.prepare('INSERT INTO sites (id, slug, title, owner_id, is_primary, created_at) VALUES (?,?,?,?,0,?)')
     35  .run('s2', 'oma', 'oma', 'u1', '2026-06-01 00:00:00');
    3236
    3337const app = express();
     
    8690});
    8791
     92test('a bare host resolves even when no site carries the primary flag', async () => {
     93  // This is the state a fresh instance is actually in: is_primary defaults to 0
     94  // and the backfill only runs when the column is first added, so a site created
     95  // afterwards leaves the instance with no primary at all. The HTML side coped
     96  // (getPrimarySite falls back to the oldest) while this route kept its own
     97  // is_primary-only lookup — so / served the site and WebFinger said 404.
     98  db.prepare('UPDATE sites SET is_primary = 0').run();
     99  try {
     100    const { status, body } = await finger('acct:test.example@test.example');
     101    assert.equal(status, 200, 'an unflagged instance is still discoverable');
     102    assert.equal(actorOf(body), 'https://test.example/ap/users/kid', 'falls back to the oldest site');
     103  } finally {
     104    db.prepare('UPDATE sites SET is_primary = 1 WHERE id = ?').run('s1');
     105  }
     106});
     107
    88108test('an unknown user is still a 404', async () => {
    89109  // The fallback must not turn every miss into the primary actor, or a typo
Note: See TracChangeset for help on using the changeset viewer.