Skip to content

Instantly share code, notes, and snippets.

View smartinm's full-sized avatar

Sergio Martín Morillas smartinm

View GitHub Profile
@smartinm
smartinm / html_capybara.rb
Created October 26, 2015 11:40
How to print HTML of elements in Capybara
element = page.find("div.example")
p element.native.attribute('outerHTML')
# Install new curl version from homebrew
$ brew install curl
# Convert cert to p12 format
$ openssl pkcs12 -export -out certificate.pfx -inkey private.key -in cert.crt -certfile ca_cert.pem
# Execute curl
$ /usr/local/opt/curl/bin/curl --cert certificate.pfx:PASSWORD -k https://url/
@smartinm
smartinm / valid_rails42_authenticity_token.coffee
Last active October 15, 2015 09:01
In order to mitigate SSL attacks, form_authenticity_token is now masked so that it varies with each request. Thus, tokens are validated by unmasking and then decrypting. As a result, any strategies for verifying requests from non-rails forms that relied on a static session CSRF token have to take this into account.
bufferEqual = require('buffer-equal')
authenticityTokenLength = 32
unmaskCSRFToken= (maskedToken) ->
if maskedToken.length == authenticityTokenLength
return maskedToken
else if maskedToken.length == authenticityTokenLength * 2
oneTimePad = maskedToken.slice(0, authenticityTokenLength)
encryptedToken = maskedToken.slice(authenticityTokenLength)