Skip to content

Commit a1aea70

Browse files
committed
fixed tag xss issue
1 parent 45ec53e commit a1aea70

File tree

12 files changed

+70
-19
lines changed

12 files changed

+70
-19
lines changed

dist/css/print.css

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -832,6 +832,11 @@
832832
.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation div.heading ul.options li a {
833833
text-decoration: none;
834834
}
835+
.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation div.heading ul.options li a .markdown p {
836+
color: inherit;
837+
padding: 0;
838+
line-height: inherit;
839+
}
835840
.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation div.heading ul.options li.access {
836841
color: black;
837842
}

dist/css/screen.css

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -832,6 +832,11 @@
832832
.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation div.heading ul.options li a {
833833
text-decoration: none;
834834
}
835+
.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation div.heading ul.options li a .markdown p {
836+
color: inherit;
837+
padding: 0;
838+
line-height: inherit;
839+
}
835840
.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation div.heading ul.options li.access {
836841
color: black;
837842
}

dist/swagger-ui.js

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -333,9 +333,9 @@ templates['operation'] = template({"1":function(container,depth0,helpers,partial
333333
+ alias3((helpers.sanitize || (depth0 && depth0.sanitize) || alias2).call(alias1,(depth0 != null ? depth0.encodedParentId : depth0),{"name":"sanitize","hash":{},"data":data}))
334334
+ "/"
335335
+ alias3((helpers.sanitize || (depth0 && depth0.sanitize) || alias2).call(alias1,(depth0 != null ? depth0.nickname : depth0),{"name":"sanitize","hash":{},"data":data}))
336-
+ "' class=\"toggleOperation\">"
336+
+ "' class=\"toggleOperation\"><span class=\"markdown\">"
337337
+ ((stack1 = (helpers.escape || (depth0 && depth0.escape) || alias2).call(alias1,(depth0 != null ? depth0.summary : depth0),{"name":"escape","hash":{},"data":data})) != null ? stack1 : "")
338-
+ "</a>\n </li>\n </ul>\n </div>\n <div class='content' id='"
338+
+ "</span></a>\n </li>\n </ul>\n </div>\n <div class='content' id='"
339339
+ alias3((helpers.sanitize || (depth0 && depth0.sanitize) || alias2).call(alias1,(depth0 != null ? depth0.encodedParentId : depth0),{"name":"sanitize","hash":{},"data":data}))
340340
+ "_"
341341
+ alias3((helpers.sanitize || (depth0 && depth0.sanitize) || alias2).call(alias1,(depth0 != null ? depth0.nickname : depth0),{"name":"sanitize","hash":{},"data":data}))
@@ -3052,7 +3052,12 @@ var _sanitize = function(html) {
30523052

30533053
var sanitize =function (html) {
30543054
var _html;
3055-
if( _.isUndefined(html) || _.isNull(html) || _.isNumber(html)) {
3055+
3056+
if ( _.isUndefined(html) || _.isNull(html)) {
3057+
return new Handlebars.SafeString('');
3058+
}
3059+
3060+
if (_.isNumber(html)) {
30563061
return new Handlebars.SafeString(html);
30573062
}
30583063

@@ -21695,6 +21700,14 @@ window.SwaggerUi.utils = {
2169521700
}
2169621701

2169721702
return result;
21703+
},
21704+
21705+
sanitize: function(html) {
21706+
// Strip the script tags from the html and inline evenhandlers
21707+
html = html.replace(/<script\b[^<]*(?:(?!<\/script>)<[^<]*)*<\/script>/gi, '');
21708+
html = html.replace(/(on\w+="[^"]*")*(on\w+='[^']*')*(on\w+=\w*\(\w*\))*/gi, '');
21709+
21710+
return html;
2169821711
}
2169921712
};
2170021713
'use strict';
@@ -22388,7 +22401,7 @@ SwaggerUi.Views.MainView = Backbone.View.extend({
2238822401
id = id + '_' + counter;
2238922402
counter += 1;
2239022403
}
22391-
resource.id = id;
22404+
resource.id = SwaggerUi.utils.sanitize(id);
2239222405
resources[id] = resource;
2239322406
this.addResource(resource, this.model.auths);
2239422407
}

dist/swagger-ui.min.js

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

src/main/html/css/print.css

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -832,6 +832,11 @@
832832
.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation div.heading ul.options li a {
833833
text-decoration: none;
834834
}
835+
.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation div.heading ul.options li a .markdown p {
836+
color: inherit;
837+
padding: 0;
838+
line-height: inherit;
839+
}
835840
.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation div.heading ul.options li.access {
836841
color: black;
837842
}

src/main/html/css/screen.css

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -832,6 +832,11 @@
832832
.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation div.heading ul.options li a {
833833
text-decoration: none;
834834
}
835+
.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation div.heading ul.options li a .markdown p {
836+
color: inherit;
837+
padding: 0;
838+
line-height: inherit;
839+
}
835840
.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation div.heading ul.options li.access {
836841
color: black;
837842
}

src/main/javascript/helpers/handlebars.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,12 @@ var _sanitize = function(html) {
1111

1212
var sanitize =function (html) {
1313
var _html;
14-
if( _.isUndefined(html) || _.isNull(html) || _.isNumber(html)) {
14+
15+
if ( _.isUndefined(html) || _.isNull(html)) {
16+
return new Handlebars.SafeString('');
17+
}
18+
19+
if (_.isNumber(html)) {
1520
return new Handlebars.SafeString(html);
1621
}
1722

src/main/javascript/utils/utils.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,5 +68,13 @@ window.SwaggerUi.utils = {
6868
}
6969

7070
return result;
71+
},
72+
73+
sanitize: function(html) {
74+
// Strip the script tags from the html and inline evenhandlers
75+
html = html.replace(/<script\b[^<]*(?:(?!<\/script>)<[^<]*)*<\/script>/gi, '');
76+
html = html.replace(/(on\w+="[^"]*")*(on\w+='[^']*')*(on\w+=\w*\(\w*\))*/gi, '');
77+
78+
return html;
7179
}
7280
};

src/main/javascript/view/MainView.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ SwaggerUi.Views.MainView = Backbone.View.extend({
9696
id = id + '_' + counter;
9797
counter += 1;
9898
}
99-
resource.id = id;
99+
resource.id = SwaggerUi.utils.sanitize(id);
100100
resources[id] = resource;
101101
this.addResource(resource, this.model.auths);
102102
}

src/main/less/specs.less

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -703,6 +703,11 @@
703703
font-size: 0.9em;
704704
a {
705705
text-decoration: none;
706+
.markdown p {
707+
color: inherit;
708+
padding: 0;
709+
line-height: inherit;
710+
}
706711
}
707712
}
708713
}

0 commit comments

Comments
 (0)