BlogsShopifyRack Middleware for Input Sanitization

Rack Middleware for Input Sanitization

Rack Middleware for Input Sanitization

1
posts
2013

This feature thread tracks the development and enhancement of Shopify's Rack middleware for input sanitization. Initial efforts focused on addressing issues with invalid form submissions during user login, specifically when users provided malformed shop URLs. The solution involved creating a custom Rack middleware that runs before OmniAuth to sanitize and recover bad form data, preventing errors caused by invalid URIs. This middleware utilizes a strategy pattern for different sanitization techniques, such as cleaning whitespace and handling domain name conventions.

2013

Building a Rack Middleware - Shopify

9/4/2013

This post details the creation of a custom Rack middleware to sanitize user input for shop URLs before it's processed by OmniAuth. It explains the problem of invalid URI generation due to user input errors, the decision to implement a middleware for pre-processing, and the design of the middleware. The implementation includes a strategy pattern for sanitization, with an example of a whitespace cleaning strategy that recovers shop names based on common conventions. The post also provides a basic Rack response structure and the middleware implementation itself, highlighting how arguments are passed during initialization.