tracker
All repositories: gitoria
2.1 KB
// lib/security.hl — THE SMALL DEFENCES the routes and faces share (mission SK, the security audit): a request budget (rate limit),// the caller's address as the proxy gives it, the headers every non-page answer carries.// hl:web answers the PAGES with no header hook (CSP / nosniff / frame-ancestors / referrer-policy there are hl:web's to add,// reports/SK-sec.md); the function routes and the files this app answers itself carry the headers below (imageHeaders; the text answers carry nosniff).import { now } from 'hl:time'import { envOr } from './util.hl'// imports of titles from TMDB (the search page's "add") per user and hour: TRACKER_IMPORT_PER_HOURstatic importPerHour = toNumber(envOr('TRACKER_IMPORT_PER_HOUR', '60'))// request budgets: `allowHit('login', ip, 20, 60000)` = at most 20 hits per key per window; true = go ahead. In memory, one// process per storage. The map is dropped when it holds too many keys (an address flood must not grow it forever).static budget = { counts = {} keys = 0 }static allowHit = (&cls, &key, &max, &windowMs) => {t = now()slot = cls + '|' + ((t - t % windowMs) / windowMs) + '|' + keyif (budget.keys > 20000) {budget.counts = {}budget.keys = 0}let c = budget.counts[slot]if (c == null) {c = 0budget.keys = budget.keys + 1}if (c >= max) { return false }budget.counts[slot] = c + 1return true}// the caller's address behind nginx (X-Client-IP, hybriel#25); 'direct' when there is none. Cut to 64 characters.static clientKey = (&req) => {h = req != null ? req.headers : nullif (h == null) { return 'direct' }let v = h['x-client-ip']if (v == null) { v = h['X-Client-IP'] }if (v == null || hlTypeName(v) != 'String' || v == '') { return 'direct' }return v.slice(0, 64)}// an image file's headers: its type, its caching, nosniff, and a policy that lets a browser show it and nothing else — a stored .svg// opened as a page can run no script, load nothing and is sandboxedstatic imageHeaders = (&contentType, &cache) => {return { 'Content-Type' = contentType 'Cache-Control' = cache 'X-Content-Type-Options' = 'nosniff' 'Content-Security-Policy' = "default-src 'none'; style-src 'unsafe-inline'; img-src data:; sandbox" }}
Branches
Latest commits
- d2e6d26bMerge branch 'records-park55' into mainTracker
- f567f025|||PR records: park #55, no Claude workers ruleTracker
- c21aff6bMerge branch 'records-hm55c' into mainTracker
- 9ba258d3|||PR records: HM55b resultTracker
- 64f2d300Merge branch 'records-hm55b2' into mainTracker
- ae3b80dc|||PR records: HM55b briefTracker
- 7ef3cb3bMerge branch 'records-st55' into mainTracker
- fec2e080|||PR records: STATUS HM55Tracker
- 8e174918Merge branch 'records-hm55b' into mainTracker
- b1ecee57|||PR records: HM55 stateTracker
- 28eab08cMerge branch 'records-hm55' into mainTracker
- d3edaa05|||PR records: HM55 start, PROCEDURES.mdTracker
- 3059f86cMerge branch 'records-design-rule' into mainTracker
- 421a4809|||PR records: his-design rule (Apollo 2026-11-13)Tracker
- d1390692Merge branch 'records-dp75b' into mainTracker
- a4d1a7d2|||PR records: later steps checked, branch auditTracker
- e070e16fMerge branch 'records-dp75' into mainTracker
- 642b4fa8|||PR records: DP75 day62 live, AP62 briefTracker
- bfc4ea4dMerge branch 'ap62' into mainTracker
- 2c95ac46|||PR AP62: re-vendor Hybriel set day62 (source 70341ad2, bin a54f5f08)Tracker