From: Terry Scheingeld <tscheingeld32@gmail.com>
To: unicorn-public@bogomips.org
Subject: tmpio.rb and taint mode
Date: Wed, 11 Dec 2019 11:24:59 -0500 [thread overview]
Message-ID: <CABg1sXrvGv9G6CDQxePDUqTe6N-5UpLXm7eG3YQO=dda-Cgg7A@mail.gmail.com> (raw)
tmpio.rb causes an "insecure operation" error when being run in taint
mode. This is due not to a problem in tmpio.rb but in Ruby's File
class. Here are the details on the problem and a simple workaround for
it.
I filed this bug report in February 2018:
https://bugs.ruby-lang.org/issues/14485. The problem is that when a
File object is created using an untainted string for the path, File
nevertheless changes that path to tainted. It is agreed thatit's a
bug: File should not taint an untainted path. However, efforts to fix
the bug seem to have stalled out.
Now, in tmpio.rb, a random, untainted path is generated and stored in
the Unicorn::TmpIO object. Then, a few lines later, the class attempts
to unlink that file using the path stored in the object. Because of
the bug in File, the path is now tainted, resulting in an insecure
operation error.
I propose a simple workaround. Store the path in its own variable.
Pass the variable to the Unicorn::TmpIO object, but use the original
variable to unlink the file. This technique worked in experimentation
for me. Here's a modified version of tmpio.rb.
# -*- encoding: binary -*-
# :stopdoc:
require 'tmpdir'
# some versions of Ruby had a broken Tempfile which didn't work
# well with unlinked files. This one is much shorter, easier
# to understand, and slightly faster.
class Unicorn::TmpIO < File
# creates and returns a new File object. The File is unlinked
# immediately, switched to binary mode, and userspace output
# buffering is disabled
def self.new
path = nil
fp = begin
path = "#{Dir::tmpdir}/#{rand}"
super(path, RDWR|CREAT|EXCL, 0600)
rescue Errno::EEXIST
retry
end
unlink(path)
fp.binmode
fp.sync = true
fp
end
# pretend we're Tempfile for Rack::TempfileReaper
alias close! close
end
next reply other threads:[~2019-12-11 16:25 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-12-11 16:24 Terry Scheingeld [this message]
2019-12-11 23:16 ` tmpio.rb and taint mode Eric Wong
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: http://yhbt.net/unicorn/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='CABg1sXrvGv9G6CDQxePDUqTe6N-5UpLXm7eG3YQO=dda-Cgg7A@mail.gmail.com' \
--to=tscheingeld32@gmail.com \
--cc=unicorn-public@bogomips.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
http://yhbt.net/unicorn.git/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).