gitoria

tracker

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commit2ae8a47b2ae8a47bMerge branch 'sk-sec'mre2ae8a47b/lib/images.hl

2.5 KB

  1. // lib/images.hl — THE IMAGE FILES the pages show (mission 028: out of project.hl, whose routes /posters/:name and
  2. // /profiles/:name call `imageResponse`):
  3. // /posters/<name> a title's poster (tracker.worldapi.org#4) from storage/mpackdb/posters/ — the file name is the title's
  4. // oldId + its extension (shows.hl posterName), downloaded by the sync (tmdb.hl syncPoster)
  5. // /profiles/<name> a person's photo (tracker.worldapi.org#16) from storage/mpackdb/profiles/ — downloaded on the first visit
  6. // of the person page (people.hl syncProfile)
  7. // Both fall back to a placeholder svg when the file isn't there yet (the mongo export never included the poster bytes): "no poster",
  8. // a person's "no photo" (tracker#37: /people's tiles).
  9. import { Response } from 'hl:http1'
  10. import { readBytes, exists } from 'hl:fs'
  11. import { imageHeaders } from './security.hl'
  12. static placeholderPoster = './assets/poster-placeholder.svg'
  13. static placeholderPhoto = './assets/photo-placeholder.svg'
  14. static posterNameChars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789.-_'
  15. // a plain file name: letters, digits, '.', '-', '_', at most 100 (also the genre redirect's check, project.hl genreMoved)
  16. static isSafePosterName = (&name) => {
  17. if (name == null || hlTypeName(name) != 'String' || name == '' || name.length > 100) { return false }
  18. let i = 0
  19. while (i < name.length) {
  20. if (!posterNameChars.includes(name[i])) { return false }
  21. i = i + 1
  22. }
  23. return true
  24. }
  25. static endsWithStr = (&s, suffix) => { return s.length >= suffix.length && s.slice(s.length - suffix.length) == suffix }
  26. static mimeOfPoster = (&name) => {
  27. if (endsWithStr(name, '.png')) { return 'image/png' }
  28. if (endsWithStr(name, '.webp')) { return 'image/webp' }
  29. if (endsWithStr(name, '.svg')) { return 'image/svg+xml' }
  30. return 'image/jpeg'
  31. }
  32. // the answer for `<dir>/<name>`: the file (a day in the browser's cache), else the placeholder (an hour); a name that is no
  33. // plain file name → 400 "bad <what> name"
  34. static imageResponse = (&dir, &name, &what) => {
  35. if (!isSafePosterName(name)) { return new Response('bad ' + what + ' name', { status = 400 headers = { 'Content-Type' = 'text/plain; charset=utf-8' 'X-Content-Type-Options' = 'nosniff' } }) }
  36. path = dir + '/' + name
  37. if (exists(path)) { return new Response(readBytes(path), { headers = imageHeaders(mimeOfPoster(name), 'public, max-age=86400') }) }
  38. return new Response(readBytes(what == 'photo' ? placeholderPhoto : placeholderPoster), { headers = imageHeaders('image/svg+xml', 'public, max-age=3600') })
  39. }

Branches

Latest commits

  • 2ae8a47bMerge branch 'sk-sec'mre
  • 8fee5d52sessions last 99 years (creator 2026-10-23: logins never expire; only sign out ends them)mre
  • 944ad51eSK: report reports/SK-sec.md, LOGsk
  • 415487c1SK: import budget per user + id type check, gate checkssk
  • 7b8a4f74security audit SK: nosniff + image sandbox headers, face id checks, adult follow, login budget + new session at login, guest-link budget, tests/security.mjssk
  • f0f26c5areports: T18 section (gates, boot-gate, 3x3 table, search + short-id compare)mre
  • 2a8682a1deploy.sh GATES: tests/warmstart.mjsmre
  • 3761338breports/T17-boot.md: handoff (phase table, fix, numbers so far, open proof)mre
  • 52e09eb2boot: sync window 1000 ms (the gates ask for a complete start), README boot-time sectionmre
  • c87149e8tests/warmstart.mjs: the progressive start proven over HTTP (note in the window, 503 short id, after: everything); bootBeginmre
  • 593a6350boot: resumable start-up scan, the server listens first (T17)mre
  • be4890a0reports: H2 hydration audit (no test change needed)mre
  • 1f9c8bf4re-vendor Hybriel 5406d146 (hl:web batches 9+10: #72 emits while the socket is closed delivered after reconnect, browser boot linear, faster list appends; contains int 6–14 + m406)mre
  • c1df88eddocker-compose: HL_GC_TABLE_LOAD=62 (tracker mission 048, T16 real-data numbers)mre
  • d0a82867mission 048: report, LOG (HL_GC_TABLE_LOAD=62 measured)mre
  • 2d4be66fre-vendor Hybriel 5df4eb7e (GC: HL_GC_TABLE_LOAD knob, mission 406)mre
  • 99e7c8b9tests: realdata-m035-radii, repro-t38, realdata-060-backfill ports from env (REAL_PORT, REAL_CHROME, REPRO_CHROME), defaults unchangedmre
  • 4625aa22re-vendor Hybriel 6f8a0689 (int 6–11: streaming cursors, #203 index heal + close() fix, fd403 listDir/cursor fds, hl:time browser side, hl:web batches 5+6)mre
  • a6dfd6ecdeploy: person-lookup gate (tracker#46)mre
  • 33ad4bd5Merge commit 'f57f64f'mre