Skip to content

Commit 37cbd17

Browse files
security: address PR review - graceful dev fallback, fix gunicorn path, use ARG for SHA256 override
1 parent 62f8b28 commit 37cbd17

2 files changed

Lines changed: 12 additions & 5 deletions

File tree

Dockerfile.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ RUN mkdir /mcr-install \
99

1010
WORKDIR /mcr-install
1111

12-
ENV MATLAB_RUNTIME_SHA256="b821022690804e498d2e5ad814dccb64aab17c5e4bc10a1e2a12498ef5364e0d"
12+
ARG MATLAB_RUNTIME_SHA256="b821022690804e498d2e5ad814dccb64aab17c5e4bc10a1e2a12498ef5364e0d"
13+
ENV MATLAB_RUNTIME_SHA256=${MATLAB_RUNTIME_SHA256}
1314

1415
RUN wget https://ssd.mathworks.com/supportfiles/downloads/R2021a/Release/1/deployment_files/installer/complete/glnxa64/MATLAB_Runtime_R2021a_Update_1_glnxa64.zip \
1516
&& echo "${MATLAB_RUNTIME_SHA256} MATLAB_Runtime_R2021a_Update_1_glnxa64.zip" | sha256sum -c -

fri/server/main.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,15 @@
1414

1515

1616
app = Flask(__name__)
17-
app.secret_key = os.environ.get("FLASK_SECRET_KEY")
18-
if not app.secret_key:
19-
raise RuntimeError("FLASK_SECRET_KEY environment variable not set")
17+
secret_key = os.environ.get("FLASK_SECRET_KEY")
18+
if not secret_key:
19+
# In production, require an explicit FLASK_SECRET_KEY to be set.
20+
# For local development and tests, fall back to a per-process random key
21+
# so that importing this module does not fail hard.
22+
if os.environ.get("FLASK_ENV") == "production":
23+
raise RuntimeError("FLASK_SECRET_KEY environment variable not set in production")
24+
secret_key = os.urandom(32)
25+
app.secret_key = secret_key
2026

2127
cors = CORS(app)
2228
app.config['CORS_HEADERS'] = 'Content-Type'
@@ -410,5 +416,5 @@ def openJupyter():
410416

411417
if __name__ == "__main__":
412418
# In production, use:
413-
# gunicorn -w 4 -b 0.0.0.0:5000 main:app
419+
# gunicorn -w 4 -b 0.0.0.0:5000 fri.server.main:app
414420
app.run(host="0.0.0.0", port=5000, debug=False)

0 commit comments

Comments
 (0)