0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-01-09 00:10:11 -05:00

Improve webhook URI validation

This commit is contained in:
Andrey Antukh 2022-12-14 16:21:23 +01:00
parent 6a7a25121e
commit 6ea0279c9e
9 changed files with 34 additions and 14 deletions

View file

@ -11,7 +11,8 @@
[app.worker :as wrk]
[clojure.spec.alpha :as s]
[integrant.core :as ig]
[java-http-clj.core :as http])
[java-http-clj.core :as http]
[promesa.core :as p])
(:import
java.net.http.HttpClient))
@ -34,7 +35,10 @@
(us/assert! ::client client)
(if sync?
(http/send req {:client client :as response-type})
(http/send-async req {:client client :as response-type}))))
(try
(http/send-async req {:client client :as response-type})
(catch Throwable cause
(p/rejected cause))))))
(defn req!
"A convencience toplevel function for gradual migration to a new API

View file

@ -169,6 +169,9 @@
(instance? java.net.ConnectException cause)
"connection-error"
(instance? java.lang.IllegalArgumentException cause)
"invalid-uri"
(instance? java.net.http.HttpConnectTimeoutException cause)
"timeout"
))

View file

@ -74,7 +74,8 @@
(when (>= total max-hooks-for-team)
(ex/raise :type :restriction
:code :webhooks-quote-reached
:hint (str/ffmt "can't create more than % webhooks per team" max-hooks-for-team)))))
:hint (str/ffmt "can't create more than % webhooks per team"
max-hooks-for-team)))))
(defn- insert-webhook!
[{:keys [::db/pool]} {:keys [team-id uri mtype is-active] :as params}]
@ -99,8 +100,8 @@
{::doc/added "1.17"}
[{:keys [::db/pool ::wrk/executor] :as cfg} {:keys [profile-id team-id] :as params}]
(check-edition-permissions! pool profile-id team-id)
(->> (validate-quotes! cfg params)
(p/fmap executor (fn [_] (validate-webhook! cfg nil params)))
(validate-quotes! cfg params)
(->> (validate-webhook! cfg nil params)
(p/fmap executor (fn [_] (insert-webhook! cfg params)))))
(s/def ::update-webhook

View file

@ -135,7 +135,7 @@
(letfn [(conformer [s]
(cond
(u/uri? s) s
(string? s) (u/uri s)
(string? s) (u/uri (str/trim s))
:else ::s/invalid))
(unformer [v]
(dm/str v))]

View file

@ -199,10 +199,12 @@
}
}
&.uri,
&.uri {
flex-grow: 1;
}
&.active {
width: 48%;
min-width: 300px;
min-width: 100px;
}
&.last-delivery {

View file

@ -620,7 +620,9 @@
ptk/WatchEvent
(watch [_ state _]
(let [team-id (:current-team-id state)
params (assoc params :team-id team-id)
params (-> params
(assoc :team-id team-id)
(update :uri str))
{:keys [on-success on-error]
:or {on-success identity
on-error rx/throw}} (meta params)]

View file

@ -620,7 +620,7 @@
;; WEBHOOKS SECTION
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(s/def ::uri ::us/not-empty-string)
(s/def ::uri ::us/uri)
(s/def ::mtype ::us/not-empty-string)
(s/def ::webhook-form
(s/keys :req-un [::uri ::mtype]))
@ -657,6 +657,8 @@
(let [message (cond
(= hint "unknown")
(tr "errors.webhooks.unexpected")
(= hint "invalid-uri")
(tr "errors.webhooks.invalid-uri")
(= hint "ssl-validation-error")
(tr "errors.webhooks.ssl-validation")
(= hint "timeout")

View file

@ -696,6 +696,9 @@ msgstr "Webhook updated successfully."
msgid "dashboard.webhooks.create.success"
msgstr "Webhook created successfully."
msgid "webhooks.last-delivery.success"
msgstr "Last delivery was successfull."
msgid "errors.webhooks.unexpected"
msgstr "Unexpected error on validating"
@ -705,15 +708,15 @@ msgstr "Timeout"
msgid "errors.webhooks.connection"
msgstr "Connection error, url not reacheable"
msgid "webhooks.last-delivery.success"
msgstr "Last delivery was successfull."
msgid "errors.webhooks.last-delivery"
msgstr "Last delivery was not successfull."
msgid "errors.webhooks.ssl-validation"
msgstr "Error on SSL validation."
msgid "errors.webhooks.invalid-uri"
msgstr "URL does not passes validation."
msgid "errors.webhooks.unexpected-status"
msgstr "Unexpected status %s"

View file

@ -761,6 +761,9 @@ msgstr "Error en la validación SSL."
msgid "errors.webhooks.unexpected-status"
msgstr "Estado inesperado %s"
msgid "errors.webhooks.invalid-uri"
msgstr "La URL no pasa la validacion."
#: src/app/main/ui/alert.cljs
msgid "ds.alert-ok"
msgstr "Ok"