0

I am able to inject javascript:alert `1` or javascript:alert(1) into the href field of the rails app and it is getting executed as JavaScript. Html encoding is already implemented but it doesnt encode brackets and back quotes.

How to solve this? What is the best method to prevent XSS in rails?

Anonymous Platypus
  • 1,392
  • 3
  • 18
  • 33

1 Answers1

2

You should always validate user input.

For example, since you're expecting an URL, you could check that the submitted string starts with http:// or https://.

submitted_url.start_with?('http://', 'https://')
Benoit Esnard
  • 13,942
  • 7
  • 65
  • 65