Created
March 27, 2013 19:27
-
-
Save sstelfox/5257265 to your computer and use it in GitHub Desktop.
Safely parse JSON in ruby.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'json' | |
unsafe_json = <<-EOS | |
{ | |
"json_class": "DangerousClass", | |
"command": "sudo rm -rf /" | |
} | |
EOS | |
# OH GOD WHERE DID MY SYSTEM GO!? | |
JSON.parse(unsafe_json) | |
# Lets make this safe... | |
JSON.create_id = nil | |
# Nothing bad happens ^_^ just got a hash... | |
JSON.parse(unsafe_json) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment