This template file from the module hugo-mod-replacements contains the regular expressions for all replacement codes.
There has been a clarifying discussion if this template may open a loophole for script attacks. I couldn’t see it myself at first, but the bottom line is simply: No.
Goldmark discards all HTML in the Markdown and also in the replacement codes with the default setting unsafe: false. These regular expressions are applied to the rendered Markdown, which gets cleared of all HTML tags before it’s transformed into HTML itself.