mirror of
https://github.com/kuhyx/WUT_Computer_Science.git
synced 2026-11-10 18:47:11 +01:00
156 ruff findings to 0. That takes the whole archive to 0, from 9,281.
Six of those findings were SQL injection, and they were the real ones. The
connector interpolated a username and an OAuth id straight out of the URL into
f-string SQL. With psycopg2 installed, the difference is not theoretical:
username = "x'; DROP TABLE users; --"
old: select * from users where username='x'; DROP TABLE users; --';
new: select * from users where username='x''; DROP TABLE users; --';
The old form is two statements and the second one runs. The new one is a
parameter, so the whole thing stays a string literal. Every query in that file
is parameterised now.
`get_recommendations` also called
`cursor.execute("... oauth_ID='{}'", oauth_ID)`, which is wrong twice over:
psycopg2 wants %s rather than {}, and its second argument must be a sequence,
not a bare string. That route could never have worked.
Ten blind `except Exception` handlers turned every programming error into a
500 with the message hidden. They are now the exceptions each block can
actually raise -- verified against the installed libraries, where
InvalidIdTokenError and ExpiredIdTokenError really are FirebaseError
subclasses -- and the handlers log a traceback instead of printing the
exception's str().
Three services bound `host="localhost"`. Each of them runs in a container with
a published port, on a compose bridge network, so binding loopback makes them
unreachable from both the host and their siblings. All four now read
ERSMS_HOST, which docker-compose sets to 0.0.0.0, and default to loopback when
run outside Docker. Flask's debug console executes arbitrary code, so that is
opt-in via FLASK_DEBUG too.
`movie_recommender.py` fitted the model at import: reading two CSVs and
building a 4803x4803 similarity matrix as a side effect of `import`. It failed
outright here, since the datasets are not committed. It is in `main()` now, and
the module imports cleanly. `error_decorator` was dead code that swallowed its
wrapped function's return value; it is gone.
Verified: all four modules import (the backend still needs its Firebase
credential JSON, which is not committed, exactly as before), the recommender's
helpers still pick the director out of a crew list, trim cast to three, fold
"Tom Hanks" to "tomhanks" and join a soup in the same order, and every route
parameter rename was matched by the URL rule it comes from.
Three of the four services are clean under mypy --strict. The backend keeps
four errors: flask-sqlalchemy builds `db.Model` dynamically, so `--strict`
refuses to subclass it. Migrating to a typed DeclarativeBase would rewrite both
models in an app that cannot be run here, so those four are reported in
TODO-refactor-remaining.md rather than hidden.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
105 lines
1.9 KiB
YAML
105 lines
1.9 KiB
YAML
version: '3.8'
|
|
|
|
services:
|
|
app:
|
|
build: ./connector
|
|
environment:
|
|
ERSMS_HOST: 0.0.0.0
|
|
ports:
|
|
- "5000:8090" # Adjust if your app uses a different port
|
|
depends_on:
|
|
- db
|
|
networks:
|
|
- my-bridge-network
|
|
db:
|
|
image: postgres:13
|
|
environment:
|
|
POSTGRES_DB: test_db
|
|
POSTGRES_USER: root
|
|
POSTGRES_PASSWORD: root
|
|
ports:
|
|
- 5432:5432
|
|
volumes:
|
|
- postgres_data:/var/lib/postgresql/data
|
|
- ./database/init.sql:/docker-entrypoint-initdb.d/init.sql
|
|
networks:
|
|
- my-bridge-network
|
|
|
|
pgadmin:
|
|
container_name: admin_container
|
|
image: dpage/pgadmin4
|
|
ports:
|
|
- 8080:80
|
|
environment:
|
|
PGADMIN_DEFAULT_EMAIL: admin@admin.com
|
|
PGADMIN_DEFAULT_PASSWORD: admin
|
|
networks:
|
|
- my-bridge-network
|
|
|
|
nginx:
|
|
image: nginx:latest
|
|
container_name: nginx
|
|
ports:
|
|
- "80:80"
|
|
- "443:443"
|
|
volumes:
|
|
- ./nginx/nginx.conf:/etc/nginx/conf.d/default.conf:ro
|
|
- ./nginx/ssl:/etc/ssl/certs
|
|
depends_on:
|
|
- app
|
|
networks:
|
|
- my-bridge-network
|
|
|
|
frontend:
|
|
container_name: frontend
|
|
build:
|
|
context: ./frontend
|
|
dockerfile: Dockerfile
|
|
ports:
|
|
- "8000:80"
|
|
depends_on:
|
|
- app
|
|
networks:
|
|
- my-bridge-network
|
|
movie_rec:
|
|
container_name: movie_rec
|
|
build: ./movie_recommendations
|
|
environment:
|
|
ERSMS_HOST: 0.0.0.0
|
|
ports:
|
|
- "8081:8081"
|
|
depends_on:
|
|
- db
|
|
networks:
|
|
- my-bridge-network
|
|
analitics:
|
|
container_name: analytics
|
|
build: ./analytics
|
|
environment:
|
|
ERSMS_HOST: 0.0.0.0
|
|
ports:
|
|
- "8082:8082"
|
|
depends_on:
|
|
- db
|
|
networks:
|
|
- my-bridge-network
|
|
firebase:
|
|
container_name: firebase
|
|
build: .
|
|
environment:
|
|
ERSMS_HOST: 0.0.0.0
|
|
ports:
|
|
- "8084:8084"
|
|
depends_on:
|
|
- db
|
|
networks:
|
|
- my-bridge-network
|
|
|
|
|
|
|
|
volumes:
|
|
postgres_data:
|
|
|
|
networks:
|
|
my-bridge-network:
|
|
driver: bridge |