Skip to content

Commit 6095d99

Browse files
committed
fix: Slack button URL
1 parent 5737070 commit 6095d99

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

layouts/shortcodes/slackbutton.html

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,16 @@
1111

1212
Security: Keeps HTML in a trusted template instead of inline raw HTML in Markdown, so Goldmark unsafe mode is not required.
1313
*/}}
14-
{{ $href := .Get "href" | default (.Get 0) }}
15-
{{ if not $href }}{{ errorf "slackbutton shortcode: missing required 'href' parameter" }}{{ end }}
14+
{{ $raw := .Get "href" | default (.Get 0) }}
15+
{{ if not $raw }}{{ errorf "slackbutton shortcode: missing required 'href' parameter" }}{{ end }}
16+
{{/* Strip optional markdown autolink angle brackets and whitespace */}}
17+
{{ $href := $raw | strings.TrimPrefix "<" | strings.TrimSuffix ">" | strings.TrimSpace }} {{/* Basic scheme allowlist to
18+
avoid ZgotmplZ when browsers sanitize */}} {{ $allowed :=(hasPrefix $href "https://" ) | or (hasPrefix $href "http://"
19+
) | or (hasPrefix $href "/" ) }} {{ if not $allowed }}{{
20+
errorf "slackbutton shortcode: unsupported or unsafe href '%s'" $href }}{{ end }}
1621
{{ $text := .Inner | default "Slack" }}
1722
{{ $target := .Get "target" | default "_blank" }}
1823
{{ $rel := .Get "rel" | default "noopener noreferrer" }}
1924
{{ $extra := .Get "class" }}
20-
<a href="{{ $href }}" class="slack-button{{ if $extra }} {{ $extra }}{{ end }}" target="{{ $target }}" rel="{{ $rel }}">{{ $text }}</a>
25+
<a href="{{ $href | safeURL }}" class="slack-button{{ if $extra }} {{ $extra }}{{ end }}" target="{{ $target }}"
26+
rel="{{ $rel }}">{{ $text }}</a>

0 commit comments

Comments
 (0)