App |
| <- IN
|
App Code |
/---| <- IN
| |
v |
| |
v |
Exploit |
App |
| <- IN
|
1 2 3 4 | <yaml type="yaml"> ---- !ruby/object:Evil hi: eval_me </yaml> |
"This system is very extendable/updatable because it embeds macros/scripting/programming language in data" --run like hell
-- Science of Insecurity
1 2 3 | if in_xml =~ /valid-codes/ fire_z_missiles(in_xml) end |
| IN |
Rails |[parse ]|
| |
------+----------+
App |[validate]|
|[ use ]|
| IN |
Rails | |
------+----------+
App |[parse ]|
|[validate]|
|[ use ]|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 | The Postel Principle Patch: --- ietf/postels-principle +++ ietf/postels-principle - Be liberal about what you accept. + Be definite about what you accept.(*) + + Treat inputs as a language, accept it with a matching computational + power, generate its recognizer from its grammar. + + Treat input-handling computational power as privilege, and reduce it + whenever possible. + + + (*) For the sake of your users, be definite about what you accept. + Being liberal worked best for simpler protocols and languages, + and is in fact limited to such languages; be sure to keep your + language regular or at most context free (no length fields). + Being more liberal did not work so well for early IPv4 stacks: + they were initially vulnerable to weak packet parser attacks, and + ended up eliminating many options and features from normal use. + Furthermore, presence of these options in traffic came to be regarded + as a sign of suspicious or malicious activities, to be mitigated by + traffic normalization or outright rejection. At current protocol + complexities, being liberal actually means exposing the users of your + software to intractable or malicious computations. |
Be definite about what you accept.(*)
Treat inputs as a language, accept it with a matching computational power, generate its recognizer from its grammar.
Treat input-handling computational power as privilege, and reduce it whenever possible.
1 2 3 | attr_accessible :name attr_accessible :name, :credit_rating, :as => :admin |
1 2 3 4 | params.require(:person). permit(:name, :age, pets_attributes: [ :name, :category ]) |

1 2 3 4 5 6 7 | extend Muskox::Extensions add_parser :user, type: :object, properties: { name: { type: :string }, email: { type: :string } } |
1 2 3 4 | MyParsers.parsers[:user]. parse( %!{"name":"me", "email":"x@y.com"}!) # => {"name"=>"me", "email"=>"x@y.com"} |
1 2 3 4 5 | MyParsers.parsers[:user].parse( %!{"hash_dos1":1, "hash_dos2":1, "hash_dos3":1}!) # Muskox::ParserError: # Unexpected property: [hash_dos1] at root. # Allowed properties: [name, email] |
1 2 3 4 | def login_params params.require(:user). permit(:login, :password) end |
1 2 3 4 | muskox_params :user_params do |m| m.require(:user). permit(:login, :password) end |