Skip to content

Commit

Permalink
Fix SAML login with OpenAM (#17785)
Browse files Browse the repository at this point in the history
OpenAM SAMLResponse contains "\r\n" every 76 characters
leading our SAML code to think it's not base64-encoded.

Fix by relaxing our valid base64 check to ignore all spaces.

Fixes #15567
  • Loading branch information
pawit-metabase committed Sep 8, 2021
1 parent 32c5b2a commit e10adcd
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/metabase/util.clj
Original file line number Diff line number Diff line change
Expand Up @@ -566,7 +566,9 @@
"Is `s` a Base-64 encoded string?"
^Boolean [s]
(boolean (when (string? s)
(re-matches #"^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$" s))))
(as-> s s
(str/replace s #"\s" "")
(re-matches #"^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$" s)))))

(defn decode-base64
"Decodes a Base64 string to a UTF-8 string"
Expand Down
3 changes: 3 additions & 0 deletions test/metabase/util_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,9 @@
"QQ" false
"QQ=" false
"QQ==" true
;; line breaks and spaces should be OK
"Q\rQ\n=\r\n=" true
" Q Q = = " true
;; padding has to go at the end
"==QQ" false))

Expand Down

0 comments on commit e10adcd

Please sign in to comment.