Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion agent/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -566,7 +566,7 @@ def do_mkdtemp():
try:
dirpath = tempfile.mkdtemp(suffix=suffix, prefix=prefix, dir=dirpath)
if sys.platform == "win32":
subprocess.call(["icacls", dirpath, "/inheritance:e", "/grant", "BUILTIN\\Users:(OI)(CI)(RX)"])
subprocess.call(["icacls", dirpath, "/inheritance:e", "/grant", "*S-1-5-32-545:(OI)(CI)(RX)"])
Copy link
Contributor

Choose a reason for hiding this comment

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

high

While using the universal SID is a great improvement for localization, this call to icacls can fail silently. The return code of subprocess.call is not checked, so if setting permissions fails, it could lead to subtle bugs later on.

It's better to use subprocess.check_call, which will raise a CalledProcessError if the command returns a non-zero exit code. This exception will be caught by the existing except block.

Additionally, extracting the magic string "*S-1-5-32-545:(OI)(CI)(RX)" into a well-named variable would improve code readability and maintainability.

Suggested change
subprocess.call(["icacls", dirpath, "/inheritance:e", "/grant", "*S-1-5-32-545:(OI)(CI)(RX)"])
# Grant BUILTIN\Users Read & Execute permissions using its well-known SID to support non-English Windows.
# See: https://learn.microsoft.com/en-us/windows/win32/secauthz/well-known-sids
users_grant_arg = "*S-1-5-32-545:(OI)(CI)(RX)"
subprocess.check_call(["icacls", dirpath, "/inheritance:e", "/grant", users_grant_arg])

except Exception:
return json_exception("Error creating temporary directory")

Expand Down
Loading