gitoria
All repositories: gitoria
4.3 KB
// lib/apps-helpers.hl — what lib/apps.hl looks up: the URL allow-list for an app's receiver (`hook`) and `return` address, the shapes// of keys and secrets, the address of a repo's API, the one-line host of a receiver. Statics only (docs/apps-api.md §1).// Config (environment, or `.env` beside project.hl): GITORIA_APP_HOSTS = the HyperConductor bases an app's URLs may start with, written// exactly as they are used (plain http and internal IP:port included), separated by commas or spaces. Default empty = only worldapi.org.import { envOr, isHex, repoOrigin, orgOrigin } from './util.hl'static appHostsRaw = envOr('GITORIA_APP_HOSTS', '')// the configured bases: one per entry, a trailing `/` dropped; an entry that is not http:// or https:// is ignoredstatic appBases = () => {out = []for (part of appHostsRaw.replaceAll(',', ' ').split(' ')) {p = part.trim()if (p != '' && (p.startsWith('http://') || p.startsWith('https://'))) {out.push(p.endsWith('/') ? p.slice(0, p.length - 1) : p)}}return out}static bases = appBases()// a URL is one line of visible ASCII (no space, no control character, no backslash), at most 500 charactersstatic plainUrl = (u) => {if (u == null || hlTypeName(u) != 'String' || u.length == 0 || u.length > 500) { return false }let i = 0while (i < u.length) {c = u.charCodeAt(i)if (c < 33 || c > 126 || c == 92) { return false }i = i + 1}return true}// a host name: letters, digits, `-` and `.` only (so no port, no user name, no IP-with-port trick)static hostChars = (h) => {if (h == '' || h.startsWith('.') || h.endsWith('.') || h.includes('..')) { return false }let i = 0while (i < h.length) {c = h.charCodeAt(i)if (!((c >= 48 && c <= 57) || (c >= 97 && c <= 122) || c == 45 || c == 46)) { return false }i = i + 1}return true}// the host of an https:// URL as written, lower case; null when there is no clean host (a user name, a port, an empty host)static httpsHost = (u) => {rest = u.slice(8)let end = rest.lengthfor (stop of ['/', '?', '#']) {k = rest.indexOf(stop)if (k >= 0 && k < end) { end = k }}h = rest.slice(0, end).toLowerCase()return hostChars(h) ? h : null}// MAY THIS URL BE AN APP'S `hook` OR `return`? (a) https:// with host worldapi.org or one of its subdomains, or (b) the URL IS one of the configured// bases or goes on after it with `/` (so http://100.77.141.84:8100.evil does not pass). Nothing else: no redirects are ever followed.static urlAllowed = (u) => {if (!plainUrl(u)) { return false }if (u.startsWith('https://')) {h = httpsHost(u)if (h != null && (h == 'worldapi.org' || h.endsWith('.worldapi.org'))) { return true }}for (b of bases) {if (u == b || u.startsWith(b + '/')) { return true }}return false}// the host (with port) of a receiver URL, for the list on the settings pagestatic hostOfUrl = (u) => {if (u == null || hlTypeName(u) != 'String') { return '' }i = u.indexOf('://')rest = i < 0 ? u : u.slice(i + 3)let end = rest.lengthfor (stop of ['/', '?', '#']) {k = rest.indexOf(stop)if (k >= 0 && k < end) { end = k }}return rest.slice(0, end)}// `return` with `code` and `state` added (the return URL may carry a query already)static withQuery = (u, pairs) => {let out = ulet hash = ''h = u.indexOf('#')if (h >= 0) { out = u.slice(0, h) hash = u.slice(h) }let sep = out.includes('?') ? '&' : '?'for (k of pairs.keys()) {out = out + sep + k + '=' + encodeURIComponent(pairs[k])sep = '&'}return out + hash}// a key (`gak_` + 40 hex) is shaped like one, or nothing is looked upstatic keyShaped = (k) => {return k != null && hlTypeName(k) == 'String' && k.length == 44 && k.startsWith('gak_') && isHex(k.slice(4), 40)}// the API base of a repo (docs/apps-api.md §0): <slug address>/api, inside an organization <org address>/api/<name>static apiOf = (slug) => {i = slug.indexOf('/')return i < 0 ? repoOrigin(slug) + '/api' : orgOrigin(slug.slice(0, i)) + '/api/' + slug.slice(i + 1)}// the form-encoded body of the confirm page's POST: { name = value } (hex values only travel in it, nothing is decoded)static formFields = (body) => {out = {}if (body == null || hlTypeName(body) != 'String') { return out }for (pair of body.split('&')) {k = pair.indexOf('=')if (k > 0) { out[pair.slice(0, k)] = pair.slice(k + 1) }}return out}
Branches
- f1-broken-json
- f2-api-bugs
- gp-gate-ports
- heap-revert
- hl25-records
- ident-chooser-selector
- mainmain branch
- p51-public-pr-reads
- records-1112
- s25-no-session-on-login-error
- v59
- w52-person-approval
- w52b-approval-followup
- w52c-header-phone
- w53-pulls-speed-pr
- w54-repo-rename-pr
- w55-rename-org
- w56-owner-members
- w62-pr-close
- w63-force-push
- w64-org-slash
Latest commits
- fefaedd2log: tracker PR-only, HL25 startedmre
- 21aa57calog: parkmre
- e9f950a8reports: G25c soakmre
- a7783686log: deploy 9f41ffcmre
- 9f41ffc1log: W30b mergedmre
- bef635c1Merge branch 'w30b'mre
- 15b996a5Org list: keyed rows by @id, newest first, concat instead of hand loopmre
- c4f6d9e3reports: G25c growth huntmre
- b88e39f1log: privacy cleanup donemre
- bfd7826ddocs: neutral example organisation namemre
- 01b71c2edocs: neutral wording in missions, reports and logmre
- 3eeea733log: 2026-11-09 PR flow plan and membersmre
- e7c2ff1fdocs: neutral name for the apps-api reviewmre
- 120b7abdlog: step 3 queuedmre
- 358474bflog: P50 livemre
- 477d7bdcMerge branch 'p50'mre
- 00efc06fP50 reportmre
- e3f85afblog: commit mention slipmre
- 4d1a4cf4log: #25 numbersmre
- 1af0a60ddocs: H25 run() correctionmre