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
- 4a3f557eImport layouts theme ebd00b6 for W61 (startup blocked)mre
- 53ca42b2log: W60 merged, W61 W62 startedmre
- 80870a33mission W61: style passmre
- 560fd208Merge W60: helpers, bound forms, login in topics, two form fixes (gitoria#28 #32 #33)mre
- ac5ba6a4log: W60, #25 measuredmre
- 220f6342W60: record corrected form proof, full AE and remaining gapsmre
- 7e31cac5gitoria#28: restrict reply form layout to reply formsmre
- ae373cfdgitoria#28: keep each reply draft in its thread componentmre
- eeeebd5agitoria: insert a newly created organization oncemre
- 34d2d5cagitoria: clear the bound public-key textarea after creationmre
- 119e54c0W60: restore conductor-owned tracking filesmre
- 24b479e7W60: record final gates, Chrome failures and AE evidencemre
- 5e11184cW60: record partial validation, framework gaps and cleanupmre
- 20fe13fagitoria#33: centralize login and tickets connection statemre
- 859754c0gitoria#29: retain the offline note and record the framework gapmre
- d140bc04gitoria#30: reproduce the upsert ordering constraintmre
- 6960e8f8gitoria#28: keep form values in bound component membersmre
- 0db27200gitoria#32: share character checks and environment lookupmre
- 452f6a1amission W60: logic clean-upsmre
- 1448c899log: cleanup, #49 GPTBot, tracker mentions on #36mre