Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

rack-post-body-to-params

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

rack-post-body-to-params

  • 0.1.8
  • Rubygems
  • Socket score

Version published
Maintainers
1
Created
Source

= Security advice

Rack::PostBodyToParams is affected by every Rails security issue induced by YAML deserialization for HTTP POST bodys as it just uses ActionSupport for that. You should either upgrade ActiveSupport or require the 'safe_yaml' gem. As of version 0.1.6 Rack::PostBodyToParams will prevent you from initializing if the XML parser is unsafe. It defaults to ActiveSupports Hash#from_xml.

= Rack::PostBodyToParams

Parses the POST or PUT body to a Hash and put it into the FORM_HASH. Most frameworks get the params hash from there.

You want to build a XMl or JSON API not with Rails? Perhaps Sinatra[http://www.sinatrarb.com/] or Padrino[http://www.padrinorb.com/]? Are you missing the Rails feature that the body of XML and JSON POST or PUT requests are automatically parsed into the params hash? Here you go!

There is something similar already in the {rack-contrib gem}[http://github.com/rack/rack-contrib] called Rack::PostBodyContentTypeParser. Besides being even less creative with the naming Rack::PostBodyToParams sports these features:

  • Parses XML as well.
  • Uses ActiveSupport. This may also considered to be a bug but it's in almost every web-framework anyway. The following features sort of depend on it.
  • Uses ActiveSupports settings for XML & JSON parsing, mainly the parser that's used. Including Nokogiri[http://nokogiri.org/] and YAJL[http://github.com/brianmario/yajl-ruby] for more speed and less memory consumption.
  • Parsers are configurable.
  • Parse errors are returned with as status 400 and the error message of the parser.

== Howto use

just

gem install rack-post-body-to-params

(sorry for the name ;-)

and then in your config.ru or app.rb:

require 'rack/post-body-to-params' use Rack::PostBodyToParams

or

use Rack::PostBodyContentTypeParser, :content_types => ['application/xml'], :parsers => { 'application/xml' => Proc.new{|a| my_own_xml_parser a }, 'application/foo' => Proc.new{|a| my_foo_parser a } }

As you can see you can restrict Rack::PostBodyToParams to only respond to 'application/xml' or 'application/json'.

Make shure ActiveSupport is required and configured. Should look somewhat like this:

ActiveSupport::JSON.backend = 'Yajl' ActiveSupport::XmlMini.backend = 'Nokogiri'

Note that all current versions of ActiveSupport (up to 3.0.0.beta4) have a bug when requiring the yajl gem. See here for details: {Rails Ticket 4897}[https://rails.lighthouseapp.com/projects/8994/tickets/4897-yajl-backend-discovery-fails-in-activesupportjson].

Either you have to patch your ActiveSupport gem or use another parser:

ActiveSupport::JSON.backend = 'YAML'

== This is early release software. Bug reports and (even more so) fixes are highly welcome!

== Note on Patches/Pull Requests

  • Fork the project.
  • Make your feature addition or bug fix.
  • Add tests for it. This is important so I don't break it in a future version unintentionally.
  • Commit, do not mess with rakefile, version, or history. (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
  • Send me a pull request. Bonus points for topic branches.

== Copyright

Copyright (c) 2010 Niko Dittmann. See LICENSE for details.

FAQs

Package last updated on 12 Sep 2013

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc