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

Custom tmpdir arg (first try) #8

Merged
merged 3 commits into from
May 21, 2018

Conversation

matthewbauer
Copy link
Contributor

@matthewbauer matthewbauer commented May 2, 2018

Attempt to add a --tmpdir arg.

The --shared option can be very useful but also a little dangerous if
you don’t trust what’s in the /tmp directory. Giving Arx a custom
location for the temp directory should make things a little bit safer.
Most useful in this case,

$ arx tmpx --shared --tmpdir '$HOME/.cache' my.tar.bz2

This will put things in your HOME directory where you can be fairly
sure no one else has snuck in a temporary directory to fool you into
using something that is malicious.

Using /tmp as a shared directory can be exploited if you know the hash
ahead of time. Just something as simple as this,

$ tmp=$(mktemp -d tmpx-HASH)
$ echo "rm -rf /" > $tmp/run

where HASH is the hash of the dat,

can create a privilege escalation when Arx runs the /run script.

This is already (hackily) done by patching tmpx.sh in nix-bundle, but I would prefer to get it working as an are.

https://github.com/matthewbauer/nix-bundle/blob/master/default.nix#L8-L9

Attempt to add a --tmpdir arg.

The --shared option can be very useful but also a little dangerous if
you don’t trust what’s in the /tmp directory. Giving Arx a custom
location for the temp directory should make things a little bit safer.
Most useful in this case,

  $ arx tmpx --shared --tmpdir '$HOME/.cache' my.tar.bz2

This will put things in your HOME directory where you can be fairly
sure no one else has snuck in a temporary directory to fool you into
using something that is malicious.

Using /tmp as a shared directory can be exploited if you know the hash
ahead of time. Just something as simple as this,

  $ tmp=$(mktemp -d tmpx-HASH)
  $ echo "rm -rf /" > $tmp/run

  where HASH is the hash of the dat,

can create a privilege escalation when Arx runs the /run script.
Copy link
Owner

@solidsnack solidsnack left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your PR. The changes I'm requesting relate to (a) formatting and (b) shell quoting.

else
dir=/tmp/tmpx-"$token"
dir=$tmpdir/tmpx-"$token"
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$tmpdir -> "$tmpdir" for shell quoting safety.

@@ -39,9 +39,9 @@ opts() {
if $shared
then
rm_=false
dir=/tmp/tmpx-"$hash"
dir=$tmpdir/tmpx-"$hash"
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$tmpdir -> "$tmpdir" for shell quoting safety.

@@ -22,12 +22,13 @@ import Data.Hashable
data Template = Template { rm0 :: Bool, {-^ Remove tmp on run success? -}
rm1 :: Bool, {-^ Remove tmp on run error? -}
shared :: Bool, {-^ Share directory across runs? -}
tmpdir :: String, {-^ Location to store tmp files.-}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe Location for tmp files. would allow a little more space.

@@ -98,6 +101,8 @@ qPath = tokCL QualifiedPath
shared :: ArgsParser Bool
shared = True <$ arg "--shared"

tmpdir :: ArgsParser Path
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

␣::␣ArgsParser Path -> ::␣␣ArgsParser Path for consistency with surrounding code.

@@ -98,6 +101,8 @@ qPath = tokCL QualifiedPath
shared :: ArgsParser Bool
shared = True <$ arg "--shared"

tmpdir :: ArgsParser Path
= arg "--tmpdir" >> QualifiedPath
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

=␣arg "--tmpdir" >> QualifiedPath -> =␣␣arg "--tmpdir" >> QualifiedPath for consistency with surrounding code.

Fixes review issues & more.
@solidsnack solidsnack merged commit b6bdb67 into solidsnack:master May 21, 2018
@solidsnack
Copy link
Owner

I will rebuild and re-release this week. Thanks for your patch.

@solidsnack
Copy link
Owner

https://hackage.haskell.org/package/arx-0.3.0

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

Successfully merging this pull request may close these issues.

2 participants