Skip to content

Commit 013654c

Browse files
committed
preventing package@version from being turned into mailto
1 parent 8225654 commit 013654c

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

server/utils/changelog/markdown.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ import {
99
} from '../readme'
1010
import sanitizeHtml from 'sanitize-html'
1111

12+
const EMAIL_REGEX = /^[\w+\-.]+@[\w\-.]+\.[a-z]+$/i
13+
1214
export async function changelogRenderer() {
1315
const renderer = new marked.Renderer({
1416
gfm: true,
@@ -21,6 +23,10 @@ export async function changelogRenderer() {
2123
const titleAttr = title ? ` title="${title}"` : ''
2224
const plainText = text.replace(/<[^>]*>/g, '').trim()
2325

26+
if (href.startsWith('mailto:') && !EMAIL_REGEX.test(text)) {
27+
return text
28+
}
29+
2430
const intermediateTitleAttr = `${` data-title-intermediate="${plainText || title}"`}`
2531

2632
return `<a href="${href}"${titleAttr}${intermediateTitleAttr} target="_blank">${text}</a>`
@@ -105,10 +111,12 @@ export async function changelogRenderer() {
105111
}
106112

107113
return {
108-
html: convertToEmoji(
109-
marked.parse(markdown, {
110-
renderer,
111-
}) as string,
114+
html: sanitizeRawHTML(
115+
convertToEmoji(
116+
marked.parse(markdown, {
117+
renderer,
118+
}) as string,
119+
),
112120
),
113121
toc,
114122
}

server/utils/readme.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ export const ALLOWED_TAGS = [
174174

175175
export const ALLOWED_ATTR: Record<string, string[]> = {
176176
'*': ['id'], // Allow id on all tags
177-
'a': ['href', 'title', 'target', 'rel'],
177+
'a': ['href', 'title', 'target', 'rel', 'class'],
178178
'img': ['src', 'alt', 'title', 'width', 'height', 'align'],
179179
'source': ['src', 'srcset', 'type', 'media'],
180180
'button': ['class', 'title', 'type', 'aria-label', 'data-copy'],

0 commit comments

Comments
 (0)