浏览代码

fix: guard null href in urls2links after jQuery removal

DOMPurify can strip the href from anchors created by the URL regex
(e.g. script-injection attempts), leaving <a> elements with no href
attribute. getAttribute('href') returns null in that case; the previous
.match() call on null crashed with TypeError.

jQuery's .attr('href') returned undefined and .match() was never
called, so the bug was silently hidden.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
rugk 1 月之前
父节点
当前提交
936a81e055
共有 1 个文件被更改,包括 2 次插入1 次删除
  1. 2 1
      js/privatebin.js

+ 2 - 1
js/privatebin.js

@@ -444,7 +444,8 @@ window.PrivateBin = (function () {
                 strict ? purifyHtmlConfigStrictSubset : purifyHtmlConfig
                 strict ? purifyHtmlConfigStrictSubset : purifyHtmlConfig
             );
             );
             element.querySelectorAll('a').forEach(function (link) {
             element.querySelectorAll('a').forEach(function (link) {
-                if (link.getAttribute('href').match(/^(?:(?:(?:f|ht)tps?|mailto|magnet):)/i)) {
+                const href = link.getAttribute('href');
+                if (href && href.match(/^(?:(?:(?:f|ht)tps?|mailto|magnet):)/i)) {
                     link.setAttribute('target', '_blank');
                     link.setAttribute('target', '_blank');
                     link.setAttribute('rel', 'nofollow noopener noreferrer');
                     link.setAttribute('rel', 'nofollow noopener noreferrer');
                 }
                 }