Skip to content

Commit b674b6a

Browse files
authored
Merge pull request #107 from AzureAD/file600
Use 600 mode on Unix
2 parents a4d95b6 + 48bc3d7 commit b674b6a

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

msal_extensions/persistence.py

+7-2
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,11 @@ def get_location(self):
105105
raise NotImplementedError
106106

107107

108+
def _open(location):
109+
return os.open(location, os.O_RDWR | os.O_CREAT | os.O_TRUNC, 0o600)
110+
# The 600 seems no-op on NTFS/Windows, and that is fine
111+
112+
108113
class FilePersistence(BasePersistence):
109114
"""A generic persistence, storing data in a plain-text file"""
110115

@@ -117,7 +122,7 @@ def __init__(self, location):
117122
def save(self, content):
118123
# type: (str) -> None
119124
"""Save the content into this persistence"""
120-
with open(self._location, 'w+') as handle: # pylint: disable=unspecified-encoding
125+
with os.fdopen(_open(self._location), 'w+') as handle:
121126
handle.write(content)
122127

123128
def load(self):
@@ -173,7 +178,7 @@ def __init__(self, location, entropy=''):
173178
def save(self, content):
174179
# type: (str) -> None
175180
data = self._dp_agent.protect(content)
176-
with open(self._location, 'wb+') as handle:
181+
with os.fdopen(_open(self._location), 'wb+') as handle:
177182
handle.write(data)
178183

179184
def load(self):

0 commit comments

Comments
 (0)