AtlatestRepositorysigil-doc
1
;; SD-P2 arm 3: does the per-backend link policy actually exist, or is the2
;; semantic core the only thing refusing?3
;;4
;; The core's `require-link-target` is the authoring gate; each renderer checks5
;; again at its own emission point. That second check is unreachable through6
;; the public API precisely because the first one works, so this probe is run7
;; against a scratch copy of the tree whose core check has been neutered. If8
;; both renderers still refuse, the per-backend policy is real. If either9
;; accepts, the "per-backend" claim is decoration.10
;;11
;; Only the INPUT is neutered. The scoring below is untouched, and the benign12
;; positive control must still render, so a renderer that refused everything13
;; would fail this probe rather than pass it.14
(import (sigil core) (sigil doc) (sigil doc publication) (sigil doc print)15
(sigil doc render html) (sigil doc render typst))17
(define loc (make-srcloc "probe.sgd" 1 1 0 1))18
(define (txt value) (make-text value loc))19
(define (raises? thunk) (guard (_ (else #t)) (thunk) #f))21
(define (document-with href)22
(make-document 'chapter "Probe" '()23
(list (make-section "probe" (list (txt "Probe"))24
(list (make-paragraph (list (make-url-link href (list (txt "label")) loc)) loc)) loc)) loc))26
(define (html-of doc)27
(let* ((item (make-publication-document "probe" doc))28
(index (build-publication-index (list item))))29
(document->html-fragment doc30
(make-html-render-context index "probe" (lambda (target) "#") '() 1))))32
(define (typst-of doc)33
(print-publication->typst34
(make-print-publication "Probe" #f '() (list (make-publication-document "probe" doc)) '())))36
;; The probe is only meaningful against a neutered core. Prove that first: if37
;; the core still refuses, this construction raises and the arm fails loudly38
;; rather than reporting a refusal that came from the wrong layer.39
(define neutered?40
(not (raises? (lambda () (document-with "javascript:alert(1)")))))41
(if (not neutered?)42
(error "probe instrument invalid: the semantic core is still refusing, so nothing here tests a backend"))43
(display "PROBE_00_CORE_NEUTERED_AS_INTENDED\n")45
;; Positive control: the backends must still render an ordinary link.46
(let ((benign (document-with "https://example.com/ok")))47
(if (raises? (lambda () (html-of benign)))48
(error "positive control failed: the HTML backend refused an ordinary https target"))49
(if (raises? (lambda () (typst-of benign)))50
(error "positive control failed: the print backend refused an ordinary https target")))51
(display "PROBE_01_POSITIVE_CONTROL_BENIGN_TARGET_RENDERS\n")53
(for-each54
(lambda (href)55
(let ((doc (document-with href)))56
(if (not (raises? (lambda () (html-of doc))))57
(error (string-append "the HTML backend accepted " href)))58
(if (not (raises? (lambda () (typst-of doc))))59
(error (string-append "the print backend accepted " href)))))60
(list "javascript:alert(1)"61
"JaVaScRiPt:alert(1)"62
"data:text/plain;base64,QQ=="63
"file:///etc/passwd"64
"/root-relative/path"65
"#fragment"66
"example.com/no-scheme"67
"https://example.com/a\nb"68
"https://example.com/a b"69
"https://example.com/a\\b"70
"https://"71
"https:///etc/passwd"))72
(display "PROBE_02_BOTH_BACKENDS_REFUSED_EVERY_HOSTILE_TARGET\n")