Skip to content
This repository has been archived by the owner on Aug 28, 2024. It is now read-only.

Commit

Permalink
Update XSS values to be consistent with knossos
Browse files Browse the repository at this point in the history
Implements modrinth/knossos#1208
Implements modrinth/knossos#1239

Also closes modrinth/knossos#1371
  • Loading branch information
triphora committed Sep 17, 2023
1 parent ae7f7e9 commit 549514e
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion lib/helpers/parse.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,14 @@ export const configuredXss = new xss.FilterXSS({
a: [...xss.whiteList.a, 'rel'],
td: [...xss.whiteList.td, 'style'],
th: [...xss.whiteList.th, 'style'],
picture: [],
source: ['media', 'sizes', 'src', 'srcset', 'type'],
},
css: {
whiteList: {
'image-rendering': /^pixelated$/,
'text-align': /^center|left|right$/,
float: /^left|right$/,
},
},
onIgnoreTagAttr: (tag, name, value) => {
Expand Down Expand Up @@ -68,6 +71,10 @@ export const configuredXss = new xss.FilterXSS({
try {
const url = new URL(value)

if (url.hostname.includes('wsrv.nl')) {
url.searchParams.delete('errorredirect')
}

const allowedHostnames = [
'imgur.com',
'i.imgur.com',
Expand All @@ -88,9 +95,11 @@ export const configuredXss = new xss.FilterXSS({
return xss.safeAttrValue(
tag,
name,
`https://wsrv.nl/?url=${encodeURIComponent(value)}&n=-1`,
`https://wsrv.nl/?url=${encodeURIComponent(url.toString())}&n=-1`,
cssFilter
)
} else {
return xss.safeAttrValue(tag, name, url.toString(), cssFilter)
}
} catch (err) {
/* empty */
Expand Down

0 comments on commit 549514e

Please sign in to comment.