Created
May 7, 2014 04:44
-
-
Save chuckd/0c51715e4c287156aeac to your computer and use it in GitHub Desktop.
Using contracts.Ruby to avoid file access vulnerabilities
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
Contract String => PathUnder["/allowed/path"] | |
def safe_path(path) | |
"/allowed/path" + path | |
end |
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
class PathUnder < CallableClass | |
def initialize(parent) | |
@parent = parent | |
end | |
def valid?(path) | |
File.expand_path(path) =~ /^#{@parent}/ | |
end | |
def to_s | |
"path to be under #{@parent}" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment