title: How can I sanitize all params coming into a Sinatra app?
body: <p>In a similar Rails app, I was able to make a recursive Hash-checking function which then runs the Sanitize gem's clean/fragment method to remove any HTML elements from incoming params hash.  I used a before filter in the application_controller so everything gets scrubbed app-wide (it's a big app). </p>
  
  <p>Backstory: XSS attacks were possible, particularly in IE browsers, but really we just don't want any of this stuff being saved into the database anyway.  Though the ultimate goal was that JSON output didn't contain it. </p>
  
  <p>I tried to do the same thing in a Sinatra app (which has some ActiveSupport and JRuby ActiveRecord bundled in), but the Sanitize gem won't bundle, because this particular app runs in JRuby for some database reasons.  Sanitize needs Nokogiri, which in turn needs Nokogumbo, and the latter just won't build in this JRuby environment. </p>
  
  <p>So I tried doing a before filter in app.rb using Rack::Util's built in html escape method, but that blows up the app.  </p>
  
  <p>Are there any alternative ways I can think about</p>
  
  <p>1) Sanitizing all incoming params into a (JRuby) Sinatra app</p>
  
  <p>And if not, a lesser option:</p>
  
  <p>2) make it so all JSON that is parsed sanitizes values in said JSON attribute-value lists?</p>
  
  <p>PS - Part of the issue here is that an included local gem, which handles a lot of the params and does JSON rendering, is proving impossible to debug.  I'll include Pry in both the host app, and the locally linked gem, and when I try to Pry into the Gem, I can't view the params hash (it just shows as empty)–there seems to be an issue of scope.</p>