aboutsummaryrefslogtreecommitdiff
path: root/haunt/jakob/dynamic
diff options
context:
space:
mode:
Diffstat (limited to 'haunt/jakob/dynamic')
-rw-r--r--haunt/jakob/dynamic/capabilities/comments.scm14
-rw-r--r--haunt/jakob/dynamic/rate-limiter.scm1
-rw-r--r--haunt/jakob/dynamic/util.scm30
3 files changed, 36 insertions, 9 deletions
diff --git a/haunt/jakob/dynamic/capabilities/comments.scm b/haunt/jakob/dynamic/capabilities/comments.scm
index 98560b0..996c549 100644
--- a/haunt/jakob/dynamic/capabilities/comments.scm
+++ b/haunt/jakob/dynamic/capabilities/comments.scm
@@ -188,16 +188,14 @@ This is a wrapper around `get-comments-by-slug'."
(define (valid-reaction? form-data)
(and (assoc "id" form-data)
(assoc "reaction" form-data)))
- (let* ((query-string (uri-query (request-uri request)))
- (form-data (if query-string
- (decode-form query-string)
- '())))
+ (let ((form-data (decode-form body)))
(unless (assoc "id" form-data) (panic "missing param `id'"))
(unless (assoc "reaction" form-data) (panic "missing param `reaction'"))
- (let ((id (assoc-value form-data "id"))
- (reaction (assoc-value form-data "reaction"))
- (reactions (comment-reactions id)))
- (unless reactions (panic "no such comment"))
+ (let* ((id (assoc-value form-data "id"))
+ (reaction (assoc-value form-data "reaction"))
+ (reactions (comment-reactions id)))
+ (unless id (panic "no such comment"))
+ (unless (emoji? reaction) (panic "invalid reaction"))
(set-reactions id (add-reaction reactions reaction))
(values '((content-type . (application/json)))
(scm->json-string `((success . #t)))))))
diff --git a/haunt/jakob/dynamic/rate-limiter.scm b/haunt/jakob/dynamic/rate-limiter.scm
index 36450f9..24239f6 100644
--- a/haunt/jakob/dynamic/rate-limiter.scm
+++ b/haunt/jakob/dynamic/rate-limiter.scm
@@ -37,6 +37,7 @@
(define (rate-limit-for-endpoint name)
(case name
+ ((put-reaction) 1)
((get-event-rsvp) 1)
((get-event-info) 8)
((get-image) 8)
diff --git a/haunt/jakob/dynamic/util.scm b/haunt/jakob/dynamic/util.scm
index a7fd38d..f6f0382 100644
--- a/haunt/jakob/dynamic/util.scm
+++ b/haunt/jakob/dynamic/util.scm
@@ -26,7 +26,8 @@
base64-length
decode-form
date<?
- hash-append!))
+ hash-append!
+ emoji?))
(define (assoc-value alist key)
"Return the `car' of `(assoc alist key)' if truthy"
@@ -82,3 +83,30 @@ If KEY does not exist in TABLE, initialize kEY to (list ITEM)"
(if (hash-ref table key)
(hash-set! table key (cons item (hash-ref table key)))
(hash-set! table key (list item))))
+
+(define (emoji? str)
+ "Determine if `str' is an 'acceptable' emoji character
+
+Acceptable is the following subset:
+
+- The 'Emoticons' block
+- The 'Supplemental Symbols and Pictographs' block, excluding U+1F900
+ through U+1F90B
+- The hand symbols from the 'Miscellaneous Symbols and Pictographs'
+ block
+- The hand symbols from the 'Dingbats' block
+- U+1F37B and U+1F440
+
+Notably, U+1F946 isn't normally treated an emoji, but it is here. I
+think it should be! As an American, I should be able to use pictographs
+to express my God-given constitutional rights!"
+ (and (string? str)
+ (= 1 (string-length str))
+ (let ((codepoint (char->integer
+ (first (string->list str)))))
+ (or (<= #x1F600 codepoint #x1F64F)
+ (<= #x1F90C codepoint #x1F9FF)
+ (<= #x1F446 codepoint #x1F450)
+ (<= #x270A codepoint #x270D)
+ (= codepoint #x1F37B)
+ (= codepoint #x1F440)))))

© 2015 - 2026 Jakob L. Kreuze