Skip to content

Commit b0b4b5a

Browse files
committed
fix(client): set cookies.txt readable only by current user
1 parent 72f5419 commit b0b4b5a

2 files changed

Lines changed: 23 additions & 3 deletions

File tree

client/deis.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,8 @@ def request(self, *args, **kwargs):
164164
kwargs['headers'] = {'Referer': url}
165165
response = super(Session, self).request(*args, **kwargs)
166166
self.cookies.save()
167+
# set ~/.deis/cookies.txt readable only by its owner
168+
os.chmod(self.cookies.filename, 0600)
167169
return response
168170

169171

@@ -176,8 +178,9 @@ class Settings(dict):
176178

177179
def __init__(self):
178180
path = os.path.expanduser('~/.deis')
179-
if not os.path.exists(path):
180-
os.mkdir(path)
181+
# Create the $HOME/.deis dir if it doesn't exist
182+
if not os.path.isdir(path):
183+
os.mkdir(path, 0700)
181184
self._path = os.path.join(path, 'client.yaml')
182185
if not os.path.exists(self._path):
183186
with open(self._path, 'w') as f:

tests/integration_test.go

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
package tests
44

55
import (
6+
"os"
7+
"os/user"
68
"testing"
79

810
"github.com/deis/deis/tests/utils"
@@ -27,10 +29,25 @@ func TestGlobal(t *testing.T) {
2729
func cookieTest(t *testing.T, params *utils.DeisTestConfig) {
2830
// Regression test for https://github.com/deis/deis/pull/1136
2931
// Ensure that cookies are cleared on auth:register and auth:cancel
32+
user, err := user.Current()
33+
if err != nil {
34+
t.Fatal(err)
35+
}
36+
cookieJar := user.HomeDir + "/.deis/cookies.txt"
3037
utils.Execute(t, authRegisterCmd, params, false, "")
31-
cmd := "cat ~/.deis/cookies.txt"
38+
cmd := "cat " + cookieJar
3239
utils.CheckList(t, cmd, params, "csrftoken", false)
3340
utils.CheckList(t, cmd, params, "sessionid", false)
41+
info, err := os.Stat(cookieJar)
42+
if err != nil {
43+
t.Fatal(err)
44+
}
45+
mode := info.Mode().String()
46+
expected := "-rw-------"
47+
if mode != expected {
48+
t.Fatalf("%s has wrong mode:\n current: %s\n expected: %s",
49+
cookieJar, mode, expected)
50+
}
3451
utils.AuthCancel(t, params)
3552
utils.CheckList(t, cmd, params, "csrftoken", true)
3653
utils.CheckList(t, cmd, params, "sessionid", true)

0 commit comments

Comments
 (0)