Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[xss] - XSS via filename #31

Open
pwnetrationguru opened this issue Jun 10, 2014 · 1 comment
Open

[xss] - XSS via filename #31

pwnetrationguru opened this issue Jun 10, 2014 · 1 comment

Comments

@pwnetrationguru
Copy link

https://github.com/grevory/bootstrap-file-input/blob/master/bootstrap.file-input.js#L112:

$(this).parent().after('<span class="file-input-name">'+fileName+'</span>');

This opens up users of this library to XSS attacks [1]. fileName should be escaped before it is used inside raw HTML.

[1] https://www.owasp.org/index.php/Cross-site_Scripting_(XSS)

@pwnetrationguru
Copy link
Author

I would suggest a fix that uses textContent or jQuery's text() method:

diff --git a/vendor/assets/javascripts/bootstrap-fileinput.js b/vendor/assets/javascripts/bootstrap-fileinput.js
index 9467b45..d912909 100644
--- a/vendor/assets/javascripts/bootstrap-fileinput.js
+++ b/vendor/assets/javascripts/bootstrap-fileinput.js
@@ -103,7 +103,9 @@ $.fn.bootstrapFileInput = function() {
         fileName = fileName.substring(fileName.lastIndexOf('\\')+1,fileName.length);
       }

-      $(this).parent().after('<span class="file-input-name">'+fileName+'</span>');
+      var span = jQuery('<span></span>', {"class":"file-input-name"});
+      span.text(fileName);
+      $(this).parent().after(span);
     });

   });

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant