Skip to content

Commit

Permalink
test
Browse files Browse the repository at this point in the history
  • Loading branch information
mfshao committed Nov 14, 2023
1 parent 774541d commit c78428b
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions manifestservice/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,19 @@
import os
import json

TRUSTED_CONFIG_PATH_PREFIXES = [
os.getcwd(),
"/var/gen3"
]

def validate_config_path(config_path):
for trusted_path in TRUSTED_CONFIG_PATH_PREFIXES:
if os.path.commonpath((os.path.realpath(config_path), trusted_path)) == trusted_path:
return
raise ValueError(
"Illegal config file path provided as {}".format(config_path)
)


def create_app():
app = flask.Flask(__name__)
Expand All @@ -15,9 +28,10 @@ def create_app():
config_path = os.environ.get("MANIFEST_SERVICE_CONFIG_PATH", "config.json")

try:
f = open(config_path)
config_str = f.read()
config_dict = json.loads(config_str)
validate_config_path(config_path)
with open(config_path) as f:
config_str = f.read()
config_dict = json.loads(config_str)
except Exception as e:
print(e)
raise ValueError(
Expand Down

0 comments on commit c78428b

Please sign in to comment.