From 3d62404fe4554c9e3ae4fde27d4c342816e01fc9 Mon Sep 17 00:00:00 2001 From: Nattapat Iammelap Date: Thu, 21 Aug 2025 18:45:14 +0700 Subject: [PATCH] using the content hash as the execute file name --- google-cloud-functions/google_cloud_function.py | 4 +++- lambda/lambda_function.py | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/google-cloud-functions/google_cloud_function.py b/google-cloud-functions/google_cloud_function.py index dc2d505..3caf28d 100644 --- a/google-cloud-functions/google_cloud_function.py +++ b/google-cloud-functions/google_cloud_function.py @@ -3,6 +3,7 @@ import shlex import subprocess import base64 +import hashlib # Set environment flag of MAX_EXECUTABLE, MAX_DATA_SIZE @@ -66,7 +67,8 @@ def execute(request): except ValueError: return bad_request("Timeout format invalid") - path = "/tmp/execute.sh" + hash = hashlib.sha256(executable).hexdigest().upper() + path = f"/tmp/{hash}.sh" with open(path, "w") as f: f.write(executable.decode()) diff --git a/lambda/lambda_function.py b/lambda/lambda_function.py index 893fa4e..46e354d 100644 --- a/lambda/lambda_function.py +++ b/lambda/lambda_function.py @@ -3,6 +3,7 @@ import shlex import base64 import subprocess +import hashlib HEADERS = { "content-type": "application/json", @@ -75,7 +76,8 @@ def lambda_handler(event, context): except ValueError: return bad_request("Timeout format invalid") - path = "/tmp/execute.sh" + hash = hashlib.sha256(executable).hexdigest().upper() + path = f"/tmp/{hash}.sh" with open(path, "w") as f: f.write(executable.decode())