Skip to content

Commit d96385e

Browse files
committed
Fix to filter @import CSS syntax in style tag to prevent XSS [Security Issue]
1 parent b0b417c commit d96385e

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

public/js/extra.js

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -552,17 +552,22 @@ export function finishView (view) {
552552
} catch (err) {
553553
console.warn(err)
554554
}
555-
// unescape > symbel inside the style tags
556-
view.find('style').each((key, value) => {
557-
$(value).html($(value).html().replace(/>/g, '>'))
558-
})
559555
// render title
560556
document.title = renderTitle(view)
561557
}
562558

563559
// only static transform should be here
564560
export function postProcess (code) {
565561
const result = $(`<div>${code}</div>`)
562+
// process style tags
563+
result.find('style').each((key, value) => {
564+
let html = $(value).html()
565+
// unescape > symbel inside the style tags
566+
html = html.replace(/&gt;/g, '>')
567+
// remove css @import to prevent XSS
568+
html = html.replace(/@import url\(([^)]*)\);?/gi, '')
569+
$(value).html(html)
570+
})
566571
// link should open in new window or tab
567572
result.find('a:not([href^="#"]):not([target])').attr('target', '_blank')
568573
// update continue line numbers

0 commit comments

Comments
 (0)