aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--haunt/api.scm15
1 files changed, 12 insertions, 3 deletions
diff --git a/haunt/api.scm b/haunt/api.scm
index de385dd..354e1b6 100644
--- a/haunt/api.scm
+++ b/haunt/api.scm
@@ -52,6 +52,15 @@
((values-list exp)
(call-with-values (lambda () exp) list))))
+(define (clearnet-only handler)
+ (lambda (request body)
+ (let ((originating-ip (assoc-ref (request-headers request) 'x-forwarded-for)))
+ (if (and (or (string-prefix? "127." originating-ip)
+ (string-suffix? ":1" originating-ip))
+ (not (%debug-enabled)))
+ (panic "This API is only available on the clearnet." #:code 403)
+ (handler request body)))))
+
(define (handle-api-request request body endpoint)
"Route handler for the API server."
(let ((method (request-method request))
@@ -76,9 +85,9 @@
(('POST "api" "comment") put-comment)
(('POST "api" "comment" "react") put-reaction)
- (('GET "apps" "gallery") get-gallery)
- (('GET "apps" "rsvp" "event-info") get-event-info)
- (('POST "apps" "rsvp") post-event-rsvp)
+ (('GET "apps" "gallery") (clearnet-only get-gallery))
+ (('GET "apps" "rsvp" "event-info") (clearnet-only get-event-info))
+ (('POST "apps" "rsvp") (clearnet-only post-event-rsvp))
(_ (lambda (. args) (not-found request)))))
request body))))))

© 2015 - 2026 Jakob L. Kreuze