ruby on rails - Is the use of hidden fields in forms insecure? -


for example
imagine have following form

  <%= form_for(@comment) |f| %>      <%= f.hidden_field :user_id%>     <%= f.hidden_field :article_id%>      <%= f.label :content %><br />     <%= f.text_area :content %>      <%= f.submit %>   <% end %> 

i got :user_id , :article_id values with:

comment.new(:user_id => current_user.id, :article_id => @article.id) 

when display form in browser this:

<form action="/comments" method="post">    <input some_rails_tokens_here />    <!-- area here-->   <input id="comment_user_id" name="comment[user_id]" type="hidden" value="1" />   <input id="comment_article_id" name="comment[article_id]" type="hidden" value="1" />   <!-- area here-->    <label for="comment_content">content</label><br />   <textarea id="comment_content" name="comment[content]"></textarea>    <input type="submit" /> </form> 

my question is, if changes post parameters , instead of being value :user_id => 1 changed :user_id => 2. same article.

i want believe verified rails tokens, not sure.

a hidden field in form is no more or less secure other data come user. is, it should not trivally trusted: comes user , open manipulation , specialty injection.

when data sent server, server should validate that data , not assume operation allowed/invalid based on particular user-modifiable context. depending upon needs, approaches hash checksums can used have high degree of confidence data not tampered (but again, should verified server each request!). using "session state" mitigates problem entirely keeping data out of user-manipulation land.

happy coding.


Comments

Popular posts from this blog

c# - How to set Z index when using WPF DrawingContext? -

razor - Is this a bug in WebMatrix PageData? -

visual c++ - Using relative values in array sorting ( asm ) -