Skip to content

Commit

Permalink
Revert "fix(xss): allow any query parameters in youtube embed, ported…
Browse files Browse the repository at this point in the history
… from #1001 (#1064)"

This reverts commit f34845f.
  • Loading branch information
triphora committed May 6, 2023
1 parent a6a6e73 commit c08139b
Showing 1 changed file with 3 additions and 18 deletions.
21 changes: 3 additions & 18 deletions helpers/parse.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ export const configuredXss = new xss.FilterXSS({
const allowedSources = [
{
regex:
/^https?:\/\/(www\.)?youtube(-nocookie)?\.com\/embed\/[a-zA-Z0-9_-]{11}((&|\?)\w+=\w+)*$/,
remove: ['autoplay=1'], // Prevents autoplay
/^https?:\/\/(www\.)?youtube(-nocookie)?\.com\/embed\/[a-zA-Z0-9_-]{11}(\?&autoplay=[0-1]{1})?$/,
remove: ['&autoplay=1'], // Prevents autoplay
},
{
regex: /^https?:\/\/(www\.)?discord\.com\/widget\?id=\d{18,19}(&theme=\w+)?$/,
Expand All @@ -42,22 +42,7 @@ export const configuredXss = new xss.FilterXSS({
for (const source of allowedSources) {
if (source.regex.test(value)) {
for (const remove of source.remove) {
let index = value.indexOf(remove);
do {
if (index - 1 > 0 && value.charAt(index - 1) === '?') {
// need to watch out for two things
// case where its ?stand=alone
// case where its ?followed=by&another=queryParam
if (index + remove.length < value.length && value.charAt(index + remove.length) === '&') {
value = value.replace(`${remove}&`, '');
} else if (index + remove.length >= value.length) {
value = value.replace(`?${remove}`, '');
}
} else {
value = value.replaceAll(`&${remove}`, ''); // can safely be removed
}
index = value.indexOf(remove);
} while (index !== -1);
value = value.replace(remove, '')
}
return name + '="' + xss.escapeAttrValue(value) + '"'
}
Expand Down

0 comments on commit c08139b

Please sign in to comment.