Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You don't show how you're defining your form in HTML, but I suspect you're using <code>method="get"</code> or not specifying how the browser should send the data to Sinatra and letting it default to <code>get</code>.</p> <p>If I define the form like this:</p> <pre><code>&lt;html&gt; &lt;body&gt; &lt;form action="do_form" method="get"&gt; User: &lt;input name="user"&gt;&lt;br&gt; Passwd: &lt;input type=password name="passwd"&gt;&lt;br&gt; &lt;input type="submit"&gt; &lt;/form&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>With this as my handler:</p> <pre><code>get '/do_form' do puts "got user/password" end </code></pre> <p>I'll see this in the console when I submit the form using the browser:</p> <pre><code>got user/passwd 127.0.0.1 - - [04/Jan/2013 07:43:24] "GET /do_form?user=foo&amp;passwd=bar HTTP/1.1" 200 - 0.0041 </code></pre> <p>Sinatra thinks it's safe to output the parameters received. The same thing happens if I define the form like:</p> <pre><code>&lt;form action="do_form"&gt; </code></pre> <p>If, instead, I define it like:</p> <pre><code>&lt;form action="do_form" method="post"&gt; </code></pre> <p>and use a <code>post</code> handler instead of <code>get</code>:</p> <pre><code>post '/do_form' do puts "got user/passwd" end </code></pre> <p>I see this in the logging instead:</p> <pre><code>got user/passwd 127.0.0.1 - - [04/Jan/2013 07:49:24] "POST /do_form HTTP/1.1" 200 - 0.0015 </code></pre> <p>This is the code I used to test this:</p> <pre><code>require 'sinatra' get '/' do ' &lt;html&gt; &lt;body&gt; &lt;!-- &lt;form action="do_form"&gt; --&gt; &lt;!-- &lt;form action="do_form" method="get"&gt; --&gt; &lt;form action="do_form" method="post"&gt; User: &lt;input name="user"&gt;&lt;br&gt; Passwd: &lt;input type=password name="passwd"&gt;&lt;br&gt; &lt;input type="submit"&gt; &lt;/form&gt; &lt;/body&gt; &lt;/html&gt; ' end get '/do_form' do puts "got user/passwd" end post '/do_form' do puts "got user/passwd" end </code></pre> <p>Simply change the definition of the form in the <code>get '/'</code> handler to try using either <code>post</code> or <code>get</code>.</p> <p>A <code>get</code> request puts all the parameters into the URL when the form is sent. It's understandable that Sinatra would output those parameters in its log at that point, since they were sent "in the clear" per the form's <code>get</code> definition.</p> <p>Changing the form to use <code>post</code> puts the parameters into the body of the incoming data, not as part of the URL, more effectively hiding them from prying eyes. Sinatra responds by not showing the parameters in its output.</p> <p>You, as the web-developer, have to be aware of the effect of using either <code>get</code> or <code>post</code> as the form's <code>method</code>. If you aren't in charge of the form, whoever is should have known the effect of using <code>get</code> and that it would put the parameters into the URL. A <code>password</code> field, or any fields that are <code>hidden</code> or should be invisible, can't be used in a form using <code>method="get"</code> because this is the expected and defined behavior of HTML and browsers. Either way, fix the form and the rest of the problem will be fixed.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload