by Arne Brasseur / plexus
Arne Brasseur
Freelance Ruby Dev
Twitter / Github : @plexus
Plain text == Universal data type
It’s “Pragmatic”!
Input & output are formal languages
We have tools for those
Keep the snakes out of the app
parse/generate at the app boundary
Inside the app, only apples
Photoshopped by Kythera of Anevern.
Photoshopped by Kythera of Anevern.
The most common vulnerability
More common than buffer overflows
“Classic” solution : escape_html
Rails 3 : SafeBuffer + html_safe
Whitelist > Blacklist
But : We’re still manually deciding what (not) to escape
What is a String?
a piece of text
a textual representation of HTML
a piece of text that is HTML escaped
HTML is structured data,
let’s treat it as such
A platypusis carryinga chickenin the forest
Identical “tree” is shared between speakers
Create a HTML data structure
Serialize it in one pass
HTML generation is
no longer ad-hoc
Output is
guaranteed well-formed
Output is
strict (because browsers)
A new world of programming opportunities! (a.k.a. WIN!)
An API for generating
and manipulating
HTML syntax trees
What Rack does for HTTP
Hexp does for HTML
Hexp objects are immutable
API inspired by jQuery
para = Hexp::Node.new(:p, "Emacs > vi")
div = Hexp::Node.new(:div, {class: 'troll'}, [para])
puts div.to_html
list = Hexp.build do
ol do
li "Go to Eurucamp"
li "Meet Ruby friends"
li "Troll the sh*t out of them"
end
end
toc = H[:ol, {class: 'toc'}, [
H[:li, 'Language Theory'],
H[:li, 'XSS'],
H[:li, 'Applications']
]
]
Lint / validate
Add admin links
Inline CSS/JS/images
Menus
Breadcrumbs
Forms
class BookWidget < Struct.new(:book, :tag)
include Hexp
def to_hexp
H[tag, {class: 'book', id: "book-#{book.id}"}, [
H[:h2, book.title],
H[:img, src: book.image.url]
]
]
end
end
Great for CRM / e-commerce, or for modularizing your own app
doc.replace('form.checkout') do |form|
form.add_child(discount_field)
end
discount_field = H[:div, [
H[:label, {for: 'discount'}, 'Discount code'],
H[:input, {type: 'text', name: 'discount'}]
]
]
http://github.com/plexus/hexpress
Converts Markdown to Hexp
Contains a bunch of ‘Middleware’
AddImpressJs
GraphvizDotToSVG
MakeSelfContained
Powers this presentation
Twitter/Github : @plexus
blog: http://arnebrasseur.net
Safe String Theory for the web by Steven Wittens
Structurally Fixing Injection Bugs by Peter Bex
Working with HTML in Haskell by Aditya Bhargava
A type-based solution to the “strings problem”: a fitting end to XSS and SQL-injection holes? by Tom Moertel
The Devil in Plain Text by Arne Brasseur
Speaking by Willem J.M. Levelt
An Introduction to Formal Languages and Automata by Peter Linz
The Science of Insecurity by Meredith L. Patterson
Ruby
Formless
Completely transparent, unobtrusive form populator for web applications and content scrapers
Loofah
HTML/XML manipulation and sanitization based on Nokogiri
Common Lisp
Haskell
General