Skip to content

Commit 58c7b3f

Browse files
committed
fix(xss): address PR review feedback on purify config and escaping
Updates HTMLPurifier config to use HTML 5 doctype for consistency with Html5Definition, adds URI.AllowedSchemes to block javascript: and data: URLs in sanitized HTML, and extracts the inline DOM escaping pattern into a named escapeHtml() method for readability.
1 parent bd93284 commit 58c7b3f

2 files changed

Lines changed: 14 additions & 5 deletions

File tree

config/purify.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,15 @@
4141

4242
'default' => [
4343
'Core.Encoding' => 'utf-8',
44-
'HTML.Doctype' => 'HTML 4.01 Transitional',
44+
'HTML.Doctype' => 'HTML 5',
4545
'HTML.Allowed' => 'h1,h2,h3,h4,h5,h6,b,u,strong,i,em,s,del,a[href|title],ul,ol,li,p[style],br,span,img[width|height|alt|src],blockquote',
4646
'HTML.ForbiddenElements' => '',
4747
'CSS.AllowedProperties' => 'font,font-size,font-weight,font-style,font-family,text-decoration,padding-left,color,background-color,text-align',
48+
'URI.AllowedSchemes' => [
49+
'http' => true,
50+
'https' => true,
51+
'mailto' => true,
52+
],
4853
'AutoFormat.AutoParagraph' => false,
4954
'AutoFormat.RemoveEmpty' => false,
5055
],

resources/js/components/GroupPage.vue

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -159,16 +159,20 @@ export default {
159159
haveLeft: false
160160
}
161161
},
162+
methods: {
163+
escapeHtml(str) {
164+
const el = document.createElement('span')
165+
el.textContent = str
166+
return el.innerHTML
167+
},
168+
},
162169
computed: {
163170
group() {
164171
return this.$store.getters['groups/get'](this.idgroups)
165172
},
166173
translatedHaveLeft() {
167-
const el = document.createElement('span')
168-
el.textContent = this.group.name
169-
const escapedName = el.innerHTML
170174
return this.$lang.get('groups.now_unfollowed', {
171-
name: escapedName,
175+
name: this.escapeHtml(this.group.name),
172176
link: '/group/view/' + this.group.id
173177
})
174178
}

0 commit comments

Comments
 (0)