interplane.Get Omega
Read in your language

interplane-forge

INTERPLANE Forge

Brought by drakestapleton

branch main Branches Tags History

interplane-forge / server / route.om

725 lines · 12413 bytes Raw Blame History
1note forged server/route.om: path safety, the allow-list gate, the /rad:<RID> redirect, slice dispatch.
2text tforg1 "https://interplane.io"
3text tforg2 "https://www.aienos.com"
4text tfpexp "/explore"
5text tfpcss "/assets/forge.css"
6text tfpico "/assets/favicon.svg"
7text tfprad "/rad:"
8text tfrsv1 "quick-start"
9text tfrsv2 "concepts"
10text tfrsv3 "adapter"
11text tfrsv4 "conformance"
12text tfrsv5 "status"
13text tfrsv6 "forge"
14text tfrsv7 "protocol"
15text tfrsv8 "api"
16text tfrsv9 "login"
17text tfrsv10 "logout"
18text tfrsv11 "explore"
19text tfrsv12 "settings"
20text tfrsv13 "new"
21text tfrsv14 "search"
22text tfrsv15 "stars"
23text tfrsv16 "notifications"
24text tfrsv17 "llms.txt"
25text tfrsv18 "sitemap.xml"
26text tfrsv19 "robots.txt"
27text tfrsv20 "assets"
28note ---- galaxy: the INTERPLANE front page. galaxy-live (galaxy/live.om) writes it into <data>galaxy/;
29note forged only streams those files. Served on the interplane.io base "/" alone: the page links
30note /assets/..., which under the /forge/ base would leave the forge.
31text tfgxi "galaxy/index.html"
32text tfgxc "galaxy/galaxy.css"
33text tfgxt "galaxy/tokens.css"
34text tfpgx "/galaxy"
35text tfpgxs "/galaxy/"
36text tfpgxc "/assets/galaxy.css"
37text tfpgxt "/assets/tokens.css"
38text tfgxhtm "text/html; charset=utf-8"
39text tfgxcc "public, max-age=30"
40note fgxpath: ffile = <data><t>
41fn fgxpath t view uchar * to void
42put ffilel 0 0
43for i ulong len tfdata bound 128
44ffilc get tfdata i
45end
46for k ulong len t bound 128
47ffilc get t k
48end
49end
50note fgxhas: the request came through base "/" and the page file is readable
51fn fgxhas to bool
52if ne get fbasel 0 1
53ret false
54end
55fgxpath tfgxi
56ret eq faccess ffile 0 get ffilel 0 4 0
57end
58note fgxsend: stream one galaxy file (kind 3; a missing file is 404). GET only.
59fn fgxsend t view uchar * ct view uchar * to long
60if not fget
61ret 405
62end
63fgxpath t
64put fobl 0 0
65put fkind 0 3
66fsetct ct
67fsetcc tfgxcc
68ret 200
69end
70note ---- path safety: 1 = safe. Refuses NUL / control / backslash, "//", "." and ".." segments
71note (raw or %2e-encoded), and any %2f / %5c / %00 (encoded separators and NUL).
72fn fsegdot a ulong e ulong to bool
73n = sub e a
74if eq n 1
75ret eq fpathat a 46
76end
77if eq n 2
78ret and eq fpathat a 46 eq fpathat add a 1 46
79end
80ret false
81end
82fn fpctbad i ulong to bool
83if ne fpathat i 37
84ret false
85end
86h = flow fpathat add i 1
87l = flow fpathat add i 2
88if and eq h 50 eq l 101
89ret true
90end
91if and eq h 50 eq l 102
92ret true
93end
94if and eq h 53 eq l 99
95ret true
96end
97ret and eq h 48 eq l 48
98end
99fn fpathok to bool
100n = get fpathl 0
101if or eq n 0 ge n 4096
102ret false
103end
104if ne fpathat 0 47
105ret false
106end
107s = ulong 1
108for i ulong n bound 4096
109c = fpathat i
110if or lt c 32 eq c 127
111ret false
112end
113if eq c 92
114ret false
115end
116if fpctbad i
117ret false
118end
119if and gt i 0 eq c 47
120if eq s i
121ret false
122end
123if fsegdot s i
124ret false
125end
126s = add i 1
127end
128end
129if fsegdot s n
130ret false
131end
132ret true
133end
134note ---- path segments: fseg0 / fseg1 fill fown and frepo; frest gets the remainder
135fn fsegend a ulong to ulong
136n = get fpathl 0
137j = a
138while lt j n bound 4096
139if eq fpathat j 47
140ret j
141end
142j = add j 1
143end
144ret n
145end
146note fsplit: 0 = "/", 1 = "/<a>", 2 = "/<a>/<b>[...]"; returns 9 when a segment is too long
147fn fsplit to ulong
148put fownl 0 0
149put frepol 0 0
150put frestl 0 0
151n = get fpathl 0
152if le n 1
153ret 0
154end
155e1 = fsegend 1
156if gt sub e1 1 63
157ret 9
158end
159for i ulong sub e1 1 bound 64
160put fown i fpathat add 1 i
161end
162put fownl 0 sub e1 1
163if ge add e1 1 n
164ret 1
165end
166e2 = fsegend add e1 1
167if gt sub sub e2 e1 1 127
168ret 9
169end
170for i ulong sub sub e2 e1 1 bound 128
171put frepo i fpathat add add e1 1 i
172end
173put frepol 0 sub sub e2 e1 1
174if gt sub n e2 4095
175ret 9
176end
177for i ulong sub n e2 bound 4096
178put frest i fpathat add e2 i
179end
180put frestl 0 sub n e2
181ret 2
182end
183fn fowneq t view uchar * to bool
184if ne len t get fownl 0
185ret false
186end
187for i ulong len t bound 64
188if ne get t i get fown i
189ret false
190end
191end
192ret true
193end
194fn frepoeq t view uchar * to bool
195if ne len t get frepol 0
196ret false
197end
198for i ulong len t bound 128
199if ne get t i get frepo i
200ret false
201end
202end
203ret true
204end
205note fseg1: frest's first segment is exactly t (t starts with /)
206fn fseg1 t view uchar * to bool
207if not frstpre t
208ret false
209end
210n = len t
211if eq n get frestl 0
212ret true
213end
214ret eq get frest n 47
215end
216note fgologin: 303 to <base>login (a write without a session; the social slice claims it when signed in)
217fn fgologin to long
218flocb
219floct tfrsv9
220put fkind 0 2
221ret 303
222end
223text tfwfol "follow"
224text tfwufol "unfollow"
225text tfwstar "/star"
226text tfwfav "/fav"
227text tfwust "/unstar"
228text tfwufav "/unfav"
229note fwrsess: an unclaimed social write path: POST goes to sign-in, other methods are 405
230fn fwrsess to long
231if eq get fmeth 0 3
232ret fgologin
233end
234ret 405
235end
236fn fiswr2 to bool
237if or fseg1 tfwstar fseg1 tfwfav
238ret true
239end
240ret or fseg1 tfwust fseg1 tfwufav
241end
242note fcomone: reserved one-segment forge pages that are not served yet answer 501
243fn fcomone to bool
244if or or fowneq tfrsv9 fowneq tfrsv10 fowneq tfrsv12
245ret true
246end
247ret or or fowneq tfrsv13 fowneq tfrsv15 or fowneq tfrsv16 fowneq tfrsv8
248end
249fn fisown to bool
250ret fowneq tfowner
251end
252fn frsv1 to bool
253if or or fowneq tfrsv1 fowneq tfrsv2 fowneq tfrsv3
254ret true
255end
256if or or fowneq tfrsv4 fowneq tfrsv5 fowneq tfrsv6
257ret true
258end
259if or or fowneq tfrsv7 fowneq tfrsv8 fowneq tfrsv9
260ret true
261end
262ret or fowneq tfrsv10 fowneq tfrsv11
263end
264fn frsv2 to bool
265if or or fowneq tfrsv12 fowneq tfrsv13 fowneq tfrsv14
266ret true
267end
268if or or fowneq tfrsv15 fowneq tfrsv16 fowneq tfrsv17
269ret true
270end
271ret or or fowneq tfrsv18 fowneq tfrsv19 fowneq tfrsv20
272end
273fn freserved to bool
274if frsv1
275ret true
276end
277ret frsv2
278end
279note fsetrepo: owner must be the delegate and repo in the allow-list; fills fridx / frid
280fn fsetrepo to bool
281put fridx 0 9999
282put fridl 0 0
283if not fisown
284ret false
285end
286i = frepoix
287if ge i get fan 0
288ret false
289end
290put fridx 0 i
291l = get fail i
292for k ulong l bound 64
293put frid k fridbyte i k
294end
295put fridl 0 l
296ret true
297end
298note ---- /rad:<RID>[/rest] -> 302 to /<owner>/<name>[/rest] when public, else 404. Only a project
299note that has an old Radicle id (fhasal) answers to one: in the store-reading build the key of a
300note project without one is its git id, which is never a /rad: link.
301fn fridat i ulong to bool
302l = get fail i
303if ne get fownl 0 add l 4
304ret false
305end
306for k ulong l bound 64
307if ne fridbyte i k get fown add k 4
308ret false
309end
310end
311ret true
312end
313fn fradredir to long
314if not fpre tfprad
315ret 0
316end
317for i ulong get fan 0 bound FAMAX
318if and fhasal i fridat i
319fradloc i
320ret 302
321end
322end
323ret 404
324end
325fn fradloc i ulong to void
326flocb
327floct tfowner
328flocc 47
329for k ulong get fanl i bound 128
330flocc frnbyte i k
331end
332a = add 1 get fownl 0
333n = sub get fpathl 0 a
334for k ulong n bound 4096
335flocc fpathat add a k
336end
337fqsloc
338put fkind 0 2
339end
340fn fqsloc to void
341if eq get fqsl 0 0
342ret
343end
344flocc 63
345for k ulong get fqsl 0 bound 4096
346flocc get fqs k
347end
348end
349note fslashrd: /<o>/<r>/ (lone trailing slash) -> 301 to /<o>/<r>, query kept
350fn fslashrd to long
351flocb
352floct tfowner
353flocc 47
354i = get fridx 0
355for k ulong get fanl i bound 128
356flocc frnbyte i k
357end
358fqsloc
359put fkind 0 2
360ret 301
361end
362note ---- the dispatcher. Returns the HTTP status; fob / fkind are filled.
363fn fslices to long
364r = qnroute
365if ne r 0
366ret r
367end
368r = grroute
369if ne r 0
370ret r
371end
372r = soroute
373if ne r 0
374ret r
375end
376r = dlroute
377if ne r 0
378ret r
379end
380note the git patch store (patch/, docs/API.md) holds /patches, /pulls and /pull; collab keeps /issues
381r = paroute
382if ne r 0
383ret r
384end
385r = coroute
386if ne r 0
387ret r
388end
389ret brroute
390end
391fn fget to bool
392ret eq get fmeth 0 1
393end
394note forigeq: the Origin header equals t exactly
395fn forigeq t view uchar * to bool
396if ne get forigl 0 len t
397ret false
398end
399for i ulong len t bound 256
400if ne get forig i get t i
401ret false
402end
403end
404ret true
405end
406note forigok: a POST carries no Origin (the CSRF token still decides) or one of the two public origins
407fn forigok to bool
408if eq get forigl 0 0
409ret true
410end
411if forigeq tforg1
412ret true
413end
414ret forigeq tforg2
415end
416fn froute to long
417if not fpathok
418ret 400
419end
420if and eq get fmeth 0 3 not forigok
421ret 403
422end
423r = slroute
424if ne r 0
425ret r
426end
427r = cm_route
428if ne r 0
429ret r
430end
431r = ohroute
432if ne r 0
433ret r
434end
435note the research pages and questions (research/route.om); before the split, which reads
436note /research/<slug> as an owner and a repository
437r = rxroute
438if ne r 0
439ret r
440end
441sg = fsplit
442if eq sg 9
443ret 404
444end
445put fridx 0 9999
446note /galaxy/ (with the slash) is the same page as /galaxy; asked for before the segment count
447note decides, because the split reads it as an owner with an empty repository
448if fpeq tfpgxs
449if fgxhas
450ret fgxsend tfgxi tfgxhtm
451end
452end
453if eq sg 0
454ret fpgroot
455end
456if eq sg 1
457ret fpgone
458end
459r = fradredir
460if ne r 0
461ret r
462end
463if freserved
464ret fslices0
465end
466if not fsetrepo
467r = fjsfx
468if ne r 0
469ret r
470end
471note a patch upload to a repository outside the public list is refused by the write gate first
472note (session, CSRF), then answered 404 in the plain text the uploader reads (patch/p3gate.om)
473r = paunl
474if ne r 0
475ret r
476end
477ret fnorepo
478end
479if eq get frestl 0 1
480ret fslashrd
481end
482if and fget eq get frestl 0 0
483fzprep
484if fjwant
485fjrepo
486ret 200
487end
488end
489r = fslices
490if ne r 0
491ret r
492end
493if and fget eq get frestl 0 0
494frepohome
495ret 200
496end
497if fiswr2
498ret fwrsess
499end
500if fcoming
501ret 501
502end
503ret 404
504end
505note fnorepo: /<o>/<x> where x is not a public repo: the social slice may claim it (follow); else 404
506fn fnorepo to long
507put fridx 0 9999
508r = soroute
509if ne r 0
510ret r
511end
512if not fisown
513ret 404
514end
515if ne get frestl 0 0
516ret 404
517end
518if or frepoeq tfwfol frepoeq tfwufol
519ret fwrsess
520end
521ret 404
522end
523text tfcm1 "/tree"
524text tfcm2 "/blob"
525text tfcm3 "/raw"
526text tfcm4 "/blame"
527text tfcm5 "/commits"
528text tfcm6 "/commit"
529text tfcm7 "/compare"
530text tfcm8 "/branches"
531text tfcm9 "/tags"
532text tfcm10 "/releases"
533text tfcm11 "/archive"
534text tfcm12 "/patches"
535text tfcm13 "/issues"
536text tfcm14 "/stargazers"
537text tfcm15 "/search"
538text tfcm16 "/labels"
539text tfcm17 "/star"
540text tfcm18 "/fav"
541note fcoming: a known repo feature path that no composed slice served yet: 501 "coming", not 404
542fn fcoming to bool
543if fcoma
544ret true
545end
546ret fcomb
547end
548fn fcoma to bool
549if or or fseg1 tfcm1 fseg1 tfcm2 or fseg1 tfcm3 fseg1 tfcm4
550ret true
551end
552if or or fseg1 tfcm5 fseg1 tfcm6 or fseg1 tfcm7 fseg1 tfcm8
553ret true
554end
555ret fseg1 tfcm9
556end
557fn fcomb to bool
558if or or fseg1 tfcm10 fseg1 tfcm11 or fseg1 tfcm12 fseg1 tfcm13
559ret true
560end
561if or or fseg1 tfcm14 fseg1 tfcm15 or fseg1 tfcm16 fseg1 tfcm17
562ret true
563end
564ret fseg1 tfcm18
565end
566note fslices0: reserved two-segment paths (e.g. /assets/forge.css, /login/x): the slices may claim them
567fn fslices0 to long
568if fpeq tfpcss
569if not fget
570ret 405
571end
572fcssout
573ret 200
574end
575if fpeq tfpico
576if not fget
577ret 405
578end
579ficoout
580ret 200
581end
582if eq get fbasel 0 1
583if fpeq tfpgxc
584ret fgxsend tfgxc tfctcss
585end
586if fpeq tfpgxt
587ret fgxsend tfgxt tfctcss
588end
589end
590r = fslices
591if ne r 0
592ret r
593end
594ret 404
595end
596fn fpgroot to long
597if not fget
598ret 405
599end
600r = grorder
601if ne r 0
602ret r
603end
604if fjwant
605fjexplore
606ret 200
607end
608note the root stays the explore page; the galaxy is its own page at /galaxy (fpgone), the map
609fexplore true
610ret 200
611end
612text tfpexj "/explore.json"
613text tfjsfx ".json"
614note fjsfx: /<owner>/<repo>.json (no more path) for a public repo: its forge/repo/1 JSON; 0 = not this
615fn fjsfx to long
616if ne get frestl 0 0
617ret 0
618end
619n = get frepol 0
620if le n len tfjsfx
621ret 0
622end
623b = sub n len tfjsfx
624for k ulong len tfjsfx
625if ne get frepo add b k get tfjsfx k
626ret 0
627end
628end
629put frepol 0 b
630if not fsetrepo
631put frepol 0 n
632put fridx 0 9999
633ret 0
634end
635if not fget
636ret 405
637end
638fzprep
639fjrepo
640ret 200
641end
642note fpgone: one segment: forge pages, the social slice, then the owner profile
643fn fpgone to long
644r = grorder
645if ne r 0
646ret r
647end
648note agents.json (server/agents.om) and the event stream and feed (door/, or the seam server/nodoor.om)
649r = fqaroute
650if ne r 0
651ret r
652end
653r = evroute
654if ne r 0
655ret r
656end
657if fpeq tfpexj
658if not fget
659ret 405
660end
661fjexplore
662ret 200
663end
664if fpeq tfpgx
665if fgxhas
666ret fgxsend tfgxi tfgxhtm
667end
668end
669r = fslices
670if ne r 0
671ret r
672end
673if fpeq tfpexp
674if not fget
675ret 405
676end
677if fjwant
678fjexplore
679ret 200
680end
681fexplore false
682ret 200
683end
684if fpeq tfpsrch
685if not fget
686ret 405
687end
688fqcap
689if fjwant
690fyjsrch
691ret 200
692end
693fyalt
694fsearch
695ret 200
696end
697if fpre tfprad
698ret fradredir
699end
700if or fpeq tfst fpeq tfstj
701if not fget
702ret 405
703end
704ret nsstat
705end
706if freserved
707if fcomone
708ret 501
709end
710ret 404
711end
712if not fisown
713ret 404
714end
715if not fget
716ret 405
717end
718if fjwant
719fyjprof
720ret 200
721end
722fyalt
723fprofile
724ret 200
725end