Changeset cae8ded in Klonkt
- Timestamp:
- 07/31/2026 11:03:47 AM (6 weeks ago)
- Branches:
- main
- Children:
- 0ca7e5d0
- Parents:
- 0f48411
- Files:
-
- 3 edited
-
src/services/ActivityPubService.js (modified) (2 diffs)
-
src/services/StatsService.js (modified) (1 diff)
-
test/stats-bots.test.js (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
src/services/ActivityPubService.js
r0f48411 rcae8ded 96 96 if (!addrs.length || addrs.some((a) => isBlockedIp(a.address))) throw new Error('ssrf-blocked-host'); 97 97 } 98 // One honest name on ALL outbound federation traffic (Robins vraag, 31-7): 99 // safeFetch went out with the bare Node default before, and polite fediverse 100 // citizens say who they are (some instances even refuse anonymous UAs). A 101 // caller-provided User-Agent (the EmbedResolver) still wins. 102 let _uaVer = '1.0'; 103 try { _uaVer = JSON.parse(fs.readFileSync(new URL('../../package.json', import.meta.url))).version || _uaVer; } catch { /* keep default */ } 104 const KLONKT_UA = `Klonkt/${_uaVer} (+https://klonkt.com)`; 105 98 106 export async function safeFetch(url, opts = {}, maxRedirects = 3) { 99 107 let target = url; … … 102 110 if (u.protocol !== 'https:' && u.protocol !== 'http:') throw new Error('ssrf-bad-scheme'); 103 111 await assertPublicHost(u.hostname); 104 const r = await fetch(target, { ...opts, redirect: 'manual', signal: AbortSignal.timeout(8000) }); 112 const r = await fetch(target, { 113 ...opts, 114 headers: { 'User-Agent': KLONKT_UA, ...(opts.headers || {}) }, 115 redirect: 'manual', 116 signal: AbortSignal.timeout(8000), 117 }); 105 118 const loc = (r.status >= 300 && r.status < 400) ? r.headers.get('location') : null; 106 119 if (loc && hop < maxRedirects) { target = new URL(loc, target).toString(); continue; } -
src/services/StatsService.js
r0f48411 rcae8ded 47 47 // Skip known bots/crawlers + link-preview fetchers + scripts so they don't inflate 48 48 // view/visitor-day counts. Empty UA = almost always automated. 49 const BOT_RE = /bot|crawl|spider|slurp|mediapartners|bingpreview|facebookexternalhit|whatsapp|telegram|discord|twitter|linkedin|embedly|pinterest|redditbot|applebot|petalbot|yandex|baidu|duckduckbot|semrush|ahrefs|mj12|dotbot|uptimerobot|pingdom|statuscake|headless|lighthouse|gptbot|claude|ccbot|perplexity|bytespider|amazonbot|googleother|google-read-aloud|python-requests|scrapy|curl|wget|axios|node-fetch|go-http|java\/|okhttp|libwww|httpclient|mastodon|pleroma|akkoma|misskey|calckey|firefish|friendica|hubzilla|lemmy|pixelfed|peertube|gotosocial|honk|http\.rb|activitypub /i;49 const BOT_RE = /bot|crawl|spider|slurp|mediapartners|bingpreview|facebookexternalhit|whatsapp|telegram|discord|twitter|linkedin|embedly|pinterest|redditbot|applebot|petalbot|yandex|baidu|duckduckbot|semrush|ahrefs|mj12|dotbot|uptimerobot|pingdom|statuscake|headless|lighthouse|gptbot|claude|ccbot|perplexity|bytespider|amazonbot|googleother|google-read-aloud|python-requests|scrapy|curl|wget|axios|node-fetch|go-http|java\/|okhttp|libwww|httpclient|mastodon|pleroma|akkoma|misskey|calckey|firefish|friendica|hubzilla|lemmy|pixelfed|peertube|gotosocial|honk|http\.rb|activitypub|klonkt/i; 50 50 function isBot(req) { 51 51 const ua = (req && req.headers && req.headers['user-agent']) || ''; -
test/stats-bots.test.js
r0f48411 rcae8ded 35 35 }); 36 36 37 test("a Klonkt's own embed-fetcher does not count on another Klonkt", () => { 38 const before = pv(); 39 Stats.recordPageview('s1', fakeReq({ 'user-agent': 'Mozilla/5.0 (compatible; Klonkt/1.0; +https://klonkt.com)' })); 40 assert.equal(pv(), before); 41 }); 42 37 43 test('a SIGNED request never counts, whatever the UA claims', () => { 38 44 const before = pv();
Note:
See TracChangeset
for help on using the changeset viewer.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)