Project

General

Profile

Actions

Bug #10066

closed

File.expand_path performs poor validation of absolute path

Bug #10066: File.expand_path performs poor validation of absolute path

Added by lavamunky (Peter Blay) over 11 years ago. Updated over 11 years ago.

Status:
Rejected
Assignee:
-
Target version:
-
ruby -v:
ruby 2.2.0dev (2014-07-19 trunk 46871) [x86_64-linux]
[ruby-core:63839]

Description

With File.expand_path(), if one of the arguments is of the form "~/.*", then it will search for the environment variable $HOME. If this is set to:

export HOME="/home/peter"

Then searching for File.expand_path '~/.bashrc' works as expected. If the variable is specified as:

export HOME="ls -la / #"

Then File.expand_path '~/.bashrc' works as expected and raises an ArgumentError for a non-absolute home. However this performs a poor validation on the environment variable, as this works around the issue:

export HOME="/bin/bash -c \"ls -la /\" #/home/peter"

From here File.expand_path '~/.bashrc' returns:

"/bin/bash -c \"ls -la /\" #/home/peter/.bashrc"

This potentially enables various security vulnerabilities such as command injection above, if this is passed to a function that runs commands, or could potentially allow an attacker other means of attack on privilege escalation, or to change other values within an application.
Please note that this affects both arguments for File.expand_path()

Actions

Also available in: PDF Atom