html - How to handle maliciously large input in a Rails form textarea -
i have textarea in 1 of rails forms accepts free-form input user.
client-side, can set maxlength: 500 on form prevent maliciously pasting excessively long input.
server-side, how can implement same safeguard? bypass form disabling property or post directly endpoint textarea parameter that's incredibly long. i'm assuming attack bring down server tries parse large text.
i can check length in controller (e.g. if params[:input].length < 500...) time params[] set , has had parse input.
does rails take care of type of attack? or there can/should do?
thanks!
you can add model validation, assuming storing value via active record.
validates_length_of :input, :minimum => 5, :maximum => 500, :allow_blank => true
server reject if length exceeds length. or can apply javascript before posting form checks length of textarea, let me know if need further or explanation.
Comments
Post a Comment