title: Handling Constraints for Nonexistent Routes Ruby on Rails
body: <p>I am trying to return a 404 error when certain urls are called in my application. </p>
  
  <p>In my routes.rb, i have the following</p>
  
  <pre><code>resources :motor_insurance_products, path: '/car-insurance' do
    collection do
      get '/:id' =&gt; 'motor_insurance_products#show'
    end
  end
  </code></pre>
  
  <p>Which means that this is a valid url</p>
  
  <pre><code>localhost:3000/car-insurance/product-one
  </code></pre>
  
  <p>But when a user tries a web cache deception attack and uses this url </p>
  
  <blockquote>
    <p>localhost:3000/car-insurance/product-one?field=abc/text.jpg</p>
  </blockquote>
  
  <p>This also passes and shows the correct page. </p>
  
  <p>I want when someone puts in an invalid url like this. I would like to redirect and show error code 404 page not found. How do i do it the cleanest way in ruby?</p>