Skip to content

Commit c8b6087

Browse files
fix: define allowed styles in readme (#2522)
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
1 parent 10d8adf commit c8b6087

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

app/components/Readme.vue

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ function handleClick(event: MouseEvent) {
8989
min-width: 0;
9090
/* Contain all children z-index values inside this container */
9191
isolation: isolate;
92+
contain: layout paint;
9293
}
9394
9495
/* README headings - styled by visual level (data-level), not semantic level */

server/utils/readme.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -198,9 +198,9 @@ const ALLOWED_ATTR: Record<string, string[]> = {
198198
'blockquote': ['data-callout'],
199199
'details': ['open'],
200200
'code': ['class'],
201-
'pre': ['class', 'style'],
201+
'pre': ['class'],
202202
'span': ['class', 'style'],
203-
'div': ['class', 'style', 'align'],
203+
'div': ['class', 'align'],
204204
'p': ['align'],
205205
}
206206

@@ -609,8 +609,8 @@ ${html}
609609
// Resolve image URLs (with GitHub blob → raw conversion)
610610
renderer.image = ({ href, title, text }: Tokens.Image) => {
611611
const resolvedHref = resolveImageUrl(href, packageName, repoInfo)
612-
const titleAttr = title ? ` title="${title}"` : ''
613-
const altAttr = text ? ` alt="${text}"` : ''
612+
const titleAttr = title ? ` title="${escapeHtml(title)}"` : ''
613+
const altAttr = text ? ` alt="${escapeHtml(text)}"` : ''
614614
return `<img src="${resolvedHref}"${altAttr}${titleAttr}>`
615615
}
616616

@@ -687,6 +687,13 @@ ${html}
687687
allowedTags: ALLOWED_TAGS,
688688
allowedAttributes: ALLOWED_ATTR,
689689
allowedSchemes: ['http', 'https', 'mailto'],
690+
// disallow styles other than the ones shiki emits
691+
allowedStyles: {
692+
span: {
693+
'color': [/^#[0-9a-f]{3,8}$/i],
694+
'--shiki-light': [/^#[0-9a-f]{3,8}$/i],
695+
},
696+
},
690697
// Transform img src URLs (GitHub blob → raw, relative → GitHub raw)
691698
transformTags: {
692699
// Headings are already processed to correct semantic levels by processHeading()

0 commit comments

Comments
 (0)