Skip to content
This repository was archived by the owner on Sep 1, 2025. It is now read-only.

Commit ce0a0fe

Browse files
committed
feat(build): #1159 excessive privileges
- Solve excessive privileges to temporary files - Creates a temporary file in the most secure manner possible. Signed-off-by: Robin Quintero <rohaquinlop301@gmail.com>
1 parent 8e5b6cc commit ce0a0fe

1 file changed

Lines changed: 23 additions & 1 deletion

File tree

src/cli/main/cli.py

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
import tempfile
5050
import textwrap
5151
from time import (
52+
sleep,
5253
time,
5354
)
5455
from tui import (
@@ -411,11 +412,32 @@ class Config(NamedTuple):
411412
cache: List[Dict[str, str]]
412413

413414

415+
def _get_named_temporary_file_name() -> str:
416+
attempts = 0
417+
file_name = ""
418+
while attempts < 4 and file_name == "":
419+
try:
420+
with tempfile.NamedTemporaryFile(delete=True) as file:
421+
file_name = file.name
422+
sleep(1)
423+
except FileExistsError as error:
424+
CON.out(f"Failed to create {error.filename}, retrying in 1 second...")
425+
attempts += 1
426+
sleep(1)
427+
428+
if file_name == "":
429+
with tempfile.NamedTemporaryFile(delete=True) as file:
430+
file_name = file.name
431+
sleep(1)
432+
return file_name
433+
434+
414435
def _get_config(head: str, attr_paths: str) -> Config:
415436
CON.out()
416437
CON.rule("Building project configuration")
417438
CON.out()
418-
out: str = tempfile.mktemp() # nosec
439+
440+
out: str = _get_named_temporary_file_name()
419441
code = _run(
420442
args=_nix_build(
421443
attr="config.configAsJson"

0 commit comments

Comments
 (0)