Skip to content

Commit 98cf13d

Browse files
committed
Added some XSS blocking code. We only allow <d> and <i> tags others will be prepended with disabled.
1 parent 74fc239 commit 98cf13d

5 files changed

Lines changed: 20 additions & 4 deletions

File tree

build/CommentCoreLibrary.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.

demo/debugger.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ var tests = {
1313
"test-ac-1":{"f":'tests/ACFun.json',"p":"acfun"},
1414
"test-ac-2":{"f":'tests/ac940133.json',"p":"acfun"},
1515
"test-ts-1":"tests/invalid/no_closing.xml",
16-
"test-ts-2":"tests/invalid/syntax_error.xml"
16+
"test-ts-2":"tests/invalid/syntax_error.xml",
17+
"test-ts-3":"tests/invalid/xss.xml"
1718
};
1819

1920
var debugs = {

demo/index.htm

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,8 @@ <h3>AcFun (Experimental)</h3>
5959
</div>
6060
<p>TagSoup: <br>
6161
<a id="test-ts-1" href="javascript:;">Tag Soup 1</a>,
62-
<a id="test-ts-2" href="javascript:;">Tag Soup 2</a>
62+
<a id="test-ts-2" href="javascript:;">Tag Soup 2</a>,
63+
<a id="test-ts-3" href="javascript:;">XSS</a>
6364
</p>
6465
<p>Filters: <br>
6566
<a onclick="cm.filter.setRuntimeFilter(fefx.center_dim);" href="javascript:;">Apply Center-Transparency</a><br>

src/parsers/BilibiliFormat.js

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ Bilibili Format
33
Licensed Under MIT License
44
Takes in an XMLDoc/LooseXMLDoc and parses that into a Generic Comment List
55
**/
6-
function BilibiliParser(xmlDoc, text){
6+
function BilibiliParser(xmlDoc, text, warn){
77
function fillRGB(string){
88
while(string.length < 6){
99
string = "0" + string;
@@ -18,8 +18,21 @@ function BilibiliParser(xmlDoc, text){
1818
if(xmlDoc !== null){
1919
var elems = xmlDoc.getElementsByTagName('d');
2020
}else{
21+
if(warn){
22+
if(!confirm("XML Parse Error. \n Allow tag soup parsing?\n[WARNING: This is unsafe.]")){
23+
return [];
24+
}
25+
}else{
26+
// clobber some potentially bad things
27+
text = text.replace(new RegExp("</([^id])","g"), "</disabled $1");
28+
text = text.replace(new RegExp("</(\S{2,})","g"), "</disabled $1");
29+
text = text.replace(new RegExp("<([^id/]\s)","g"), "<disabled $1");
30+
text = text.replace(new RegExp("<([^/ ]{2,}\W*?)","g"), "<disabled $1");
31+
console.log(text);
32+
}
2133
var tmp = document.createElement("div");
2234
tmp.innerHTML = text;
35+
console.log(tmp);
2336
var elems = tmp.getElementsByTagName('d');
2437
}
2538
var tlist = [];

tests/invalid/xss.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<img src="" onerror="alert()">

0 commit comments

Comments
 (0)