diff options
| author | eltrac <hi@eltr.ac> | 2026-03-03 09:32:40 +0800 |
|---|---|---|
| committer | eltrac <hi@eltr.ac> | 2026-03-03 09:32:40 +0800 |
| commit | adcd1767b5a2c7a3452780cd328e1d8a46c06fb2 (patch) | |
| tree | bfbc3bca82a593f4f4f65a57c5a6bbef864301ac /src | |
| parent | 05c66c9086c9f4a4e4cb9227e8730ad461ea8218 (diff) | |
fix: perform checks correctly
Diffstat (limited to 'src')
| -rw-r--r-- | src/weepinbell/receiver.clj | 46 |
1 files changed, 26 insertions, 20 deletions
diff --git a/src/weepinbell/receiver.clj b/src/weepinbell/receiver.clj index 756e0f7..351944c 100644 --- a/src/weepinbell/receiver.clj +++ b/src/weepinbell/receiver.clj @@ -20,31 +20,37 @@ (defn verify-request [s t] (let [checks [;; The receiver MUST check that source and target are valid URLs [URL] ;; and are of schemes that are supported by the receiver. - (validate-urls s t) "Invalid URLs. Source and target have to be http(s) urls." + [(validate-urls s t) "Invalid URLs. Source and target have to be http(s) urls."] ;; The receiver MUST reject the request ;; if the source URL is the same as the target URL. - (not (= s t)) "Source and target are identical." - (validate-target t) "Domain of target is not allowed"]] - (for [[passed? msg] checks] - (when-not passed? - {:status 400 - :body msg})))) + [(not (= s t)) "Source and target are identical."] + [(validate-target t) "Domain of target is not allowed. This receiver does not receive webmention on its behalf."]]] + (map (fn [[passed? msg]] + (when-not passed? + {:status 400 + :body msg})) + checks))) (def wmc (chan)) ;; webmention queue (defn receive [wm] - (let [{:keys [s t]} wm] + (let [{:keys [s t]} wm + verification (verify-request s t)] ;; Request verification - (verify-request s t) - ;; The receiver SHOULD check that target is a valid - ;; resource for which it can accept Webmentions. - ;; This check SHOULD happen synchronously to reject - ;; invalid Webmentions before more in-depth verification begins. - ;; - ;; Webmention verification SHOULD be handled asynchronously - ;; to prevent DoS (Denial of Service) attacks. - (go (>! wmc wm)) - {:status 202 - :headers {"Content-Type" "text/plain"} - :body "Webmention accepted"})) + (if-let [errror-response (some identity verification)] + ;; respond if request verification failed + errror-response + ;; proceed if request is ok + (do + ;; The receiver SHOULD check that target is a valid + ;; resource for which it can accept Webmentions. + ;; This check SHOULD happen synchronously to reject + ;; invalid Webmentions before more in-depth verification begins. + ;; + ;; Webmention verification SHOULD be handled asynchronously + ;; to prevent DoS (Denial of Service) attacks. + (go (>! wmc wm)) + {:status 202 + :headers {"Content-Type" "text/plain"} + :body "Webmention accepted"})))) |
