CVE-2022-4591 (Other, published 2022-12-17T19:15Z)
Description: value: A vulnerability was found in mschaef toto up to 1.4.20. It has been declared as problematic. This vulnerability affects unknown code of the component Email Parameter Handler. The manipulation leads to cross site scripting. The attack can be initiated remotely. Upgrading to version 1.4.21 is able to address this issue. The name of the patch is 1f27f37c1a06f54a76971f70eaa6139dc139bdf9. It is recommended to upgrade the affected component. VDB-216178 is the identifier assigned to this vulnerability.
Severity: nan (CVSS v3 base score: 6.1)
Weakness: CWE-79 \u2014 Improper Neutralization of Input During Web Page Generation ('Cross-site Scripting')
The product does not neutralize or incorrectly neutralizes user-controllable input before it is placed in output that is used as a web page that is served to other users.
Repository: https://github.com/mschaef/toto
Files changed:
src/toto/core/mail.clj
src/toto/core/util.clj
src/toto/site/user.clj
src/toto/view/auth.clj
Commit message: Ensure e-mail parameters are escaped to avoid XSS attacks.


Vulnerable code:

  (:use hiccup.core)
            [postal.core :as postal]))
        {to :to subject :subject content :content params :params} message-info
        html-content (html [:html (if (fn? content)
                                    (content (merge config (or params {})))
                                    content)])]
      (do
        (log/warn "E-mail disabled. Message not sent. Message text: ")
        (log/warn html-content))
      (do
        (log/warn "No destination e-mail address. Message not send. Message text: ")
        (log/warn html-content))
    "Thank you for registering with " [:a {:href (:base-url (:config params))} "Toto"]
    "account at " [:a {:href (:base-url (:config params))} "Toto"] ", the family "
    " to reset your password at " [:a {:href (:base-url (:config params))} "Toto"]

(defn password-change-message [ config ]
  (let [from-mail (get-in config [:smtp :from])]
      "account at " [:a {:href (:base-url config)} "Toto"]
                    :params config}))

Fixed code:
  (:use toto.core.util)
            [postal.core :as postal]
            [hiccup.core :as hiccup]
            [hiccup.util :as hiccup-util]))

(defn- escape-email-params [ params ]
  (map-values #(if (string? %)
                 (hiccup-util/escape-html %)
                 "")
              params))
        {:keys [ to subject content params ]} message-info
        html-content (hiccup/html
                      [:html
                       (content (escape-email-params
                                 (merge {:base-url (:base-url config)}
                                        (or params {}))))])]

      (log/warn "E-mail disabled. Message not sent. Message text: "
                html-content)
      (log/warn "No destination e-mail address. Message not send. Message text: "
                html-content)

(defn map-values [f m]
  (->> (map (fn [[k v]] [k (f v)]) m)
       (into {})))
    "Thank you for registering with " [:a {:href (:base-url params)} "Toto"]
    "account at " [:a {:href (:base-url params)} "Toto"] ", the family "
    " to reset your password at " [:a {:href (:base-url params)} "Toto"]
(defn password-change-message [ params ]
  (let [ { :keys [ from-mail ]} params ]
      "account at " [:a {:href (:base-url params)} "Toto"]
                    :params { :from-mail (get-in config [:smtp :from]) }}))