🐛 Add proper validation of registration domain whitelist on oidc

Fixes #3348
This commit is contained in:
Andrey Antukh 2023-06-26 18:10:43 +02:00
parent f60d09eb8f
commit f166fe1926
5 changed files with 60 additions and 38 deletions

View file

@ -6,7 +6,9 @@
(ns app.auth
(:require
[app.config :as cf]
[buddy.hashers :as hashers]
[cuerdas.core :as str]
[promesa.exec :as px]))
(def default-params
@ -27,3 +29,16 @@
{:update false
:valid false})))
(defn email-domain-in-whitelist?
"Returns true if email's domain is in the given whitelist or if
given whitelist is an empty string."
([email]
(let [domains (cf/get :registration-domain-whitelist)]
(email-domain-in-whitelist? domains email)))
([domains email]
(if (or (nil? domains) (empty? domains))
true
(let [[_ candidate] (-> (str/lower email)
(str/split #"@" 2))]
(contains? domains candidate)))))