Skip to content

Commit c361baa

Browse files
committed
fix: Added smaller fixes addressing several LLM bug reports
1 parent 28a29db commit c361baa

9 files changed

Lines changed: 56 additions & 9 deletions

File tree

‎dist/purify.cjs.js‎

Lines changed: 12 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎dist/purify.cjs.js.map‎

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎dist/purify.es.mjs‎

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -600,7 +600,7 @@ function createDOMPurify() {
600600
/* Parse profile info */
601601
if (USE_PROFILES) {
602602
ALLOWED_TAGS = addToSet({}, text);
603-
ALLOWED_ATTR = [];
603+
ALLOWED_ATTR = create(null);
604604
if (USE_PROFILES.html === true) {
605605
addToSet(ALLOWED_TAGS, html$1);
606606
addToSet(ALLOWED_ATTR, html);
@@ -621,6 +621,13 @@ function createDOMPurify() {
621621
addToSet(ALLOWED_ATTR, xml);
622622
}
623623
}
624+
/* Prevent function-based ADD_ATTR / ADD_TAGS from leaking across calls */
625+
if (!objectHasOwnProperty(cfg, 'ADD_TAGS')) {
626+
EXTRA_ELEMENT_HANDLING.tagCheck = null;
627+
}
628+
if (!objectHasOwnProperty(cfg, 'ADD_ATTR')) {
629+
EXTRA_ELEMENT_HANDLING.attributeCheck = null;
630+
}
624631
/* Merge configuration parameters */
625632
if (cfg.ADD_TAGS) {
626633
if (typeof cfg.ADD_TAGS === 'function') {
@@ -1018,6 +1025,10 @@ function createDOMPurify() {
10181025
*/
10191026
// eslint-disable-next-line complexity
10201027
const _isValidAttribute = function _isValidAttribute(lcTag, lcName, value) {
1028+
/* FORBID_ATTR must always win, even if ADD_ATTR predicate would allow it */
1029+
if (FORBID_ATTR[lcName]) {
1030+
return false;
1031+
}
10211032
/* Make sure attribute cannot clobber */
10221033
if (SANITIZE_DOM && (lcName === 'id' || lcName === 'name') && (value in document || value in formElement)) {
10231034
return false;

‎dist/purify.es.mjs.map‎

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎dist/purify.js‎

Lines changed: 12 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎dist/purify.js.map‎

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎dist/purify.min.js‎

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎dist/purify.min.js.map‎

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎src/purify.ts‎

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -610,7 +610,7 @@ function createDOMPurify(window: WindowLike = getGlobal()): DOMPurify {
610610
/* Parse profile info */
611611
if (USE_PROFILES) {
612612
ALLOWED_TAGS = addToSet({}, TAGS.text);
613-
ALLOWED_ATTR = [];
613+
ALLOWED_ATTR = create(null);
614614
if (USE_PROFILES.html === true) {
615615
addToSet(ALLOWED_TAGS, TAGS.html);
616616
addToSet(ALLOWED_ATTR, ATTRS.html);
@@ -635,6 +635,15 @@ function createDOMPurify(window: WindowLike = getGlobal()): DOMPurify {
635635
}
636636
}
637637

638+
/* Prevent function-based ADD_ATTR / ADD_TAGS from leaking across calls */
639+
if (!objectHasOwnProperty(cfg, 'ADD_TAGS')) {
640+
EXTRA_ELEMENT_HANDLING.tagCheck = null;
641+
}
642+
643+
if (!objectHasOwnProperty(cfg, 'ADD_ATTR')) {
644+
EXTRA_ELEMENT_HANDLING.attributeCheck = null;
645+
}
646+
638647
/* Merge configuration parameters */
639648
if (cfg.ADD_TAGS) {
640649
if (typeof cfg.ADD_TAGS === 'function') {
@@ -1202,6 +1211,11 @@ function createDOMPurify(window: WindowLike = getGlobal()): DOMPurify {
12021211
lcName: string,
12031212
value: string
12041213
): boolean {
1214+
/* FORBID_ATTR must always win, even if ADD_ATTR predicate would allow it */
1215+
if (FORBID_ATTR[lcName]) {
1216+
return false;
1217+
}
1218+
12051219
/* Make sure attribute cannot clobber */
12061220
if (
12071221
SANITIZE_DOM &&

0 commit comments

Comments
 (0)