-
-
Notifications
You must be signed in to change notification settings - Fork 113
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This should help prevent automated spam signups. Implements #628.
- Loading branch information
Showing
11 changed files
with
161 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -40,6 +40,10 @@ | |
:client-secret #profile {:production #ssm-parameter "/clojars/production/gitlab_oauth_client_secret" | ||
:default "testing"} | ||
:callback-uri "https://clojars.org/oauth/gitlab/callback"} | ||
:hcaptcha #profile {:production {:site-key #ssm-parameter "/clojars/production/hcaptcha_site_key" | ||
:secret #ssm-parameter "/clojars/production/hcaptcha_secret"} | ||
:default {:site-key "10000000-ffff-ffff-ffff-000000000001" | ||
:secret "0x0000000000000000000000000000000000000000"}} | ||
:index-path "data/index" | ||
:mail #profile {:production {:from "[email protected]" | ||
:hostname "email-smtp.us-east-1.amazonaws.com" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
(ns clojars.hcaptcha | ||
"See https://docs.hcaptcha.com/#verify-the-user-response-server-side" | ||
(:require | ||
[clojars.log :as log] | ||
[clojars.remote-service :as remote-service :refer [defendpoint]] | ||
[clojure.set :as set])) | ||
|
||
(def hcaptcha-csp | ||
(let [hcaptcha-urls ["https://hcaptcha.com" "https://*.hcaptcha.com"]] | ||
{:connect-src hcaptcha-urls | ||
:frame-src hcaptcha-urls | ||
:script-src hcaptcha-urls | ||
:style-src hcaptcha-urls})) | ||
|
||
(defrecord Hcaptcha [config]) | ||
|
||
(defn site-key | ||
[hcaptcha] | ||
(get-in hcaptcha [:config :site-key])) | ||
|
||
(defn- secret | ||
[hcaptcha] | ||
(get-in hcaptcha [:config :secret])) | ||
|
||
(defendpoint -validate-hcaptcha-response | ||
[_client site-key secret hcaptcha-response] | ||
{:method :post | ||
:url "https://api.hcaptcha.com/siteverify" | ||
:form-params {:response hcaptcha-response | ||
:secret secret | ||
:site-key site-key}}) | ||
|
||
;; These responses from hcaptcha indicate a misconfiguration or a code bug, so | ||
;; we will throw and error for them. | ||
(def ^:private invalid-error-codes | ||
#{"bad-request" | ||
"invalid-input-secret" | ||
"invalid-or-already-seen-response" | ||
"missing-input-secret" | ||
"sitekey-secret-mismatch"}) | ||
|
||
(defn- log-and-maybe-thrpw | ||
[{:as _response :keys [error-codes success]}] | ||
(let [log-data {:tag :hcaptcha-response | ||
:error-codes error-codes | ||
:success? success}] | ||
(log/info log-data) | ||
(when (seq (set/intersection invalid-error-codes (set error-codes))) | ||
(throw (ex-info "Invalid hcaptcha configuration" log-data))))) | ||
|
||
(defn valid-response? | ||
[hcaptcha hcaptcha-response] | ||
(let [response (-validate-hcaptcha-response (:client hcaptcha) | ||
(site-key hcaptcha) | ||
(secret hcaptcha) | ||
hcaptcha-response)] | ||
(log-and-maybe-thrpw response) | ||
(:success response))) | ||
|
||
(defn new-hcaptcha | ||
[config] | ||
(map->Hcaptcha {:config config | ||
:client (remote-service/new-http-remote-service)})) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,7 +32,7 @@ | |
|
||
java.util.List | ||
(redact [v] | ||
(vec (map redact v))) | ||
(mapv redact v)) | ||
|
||
java.util.Map | ||
(redact [v] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.