security
This commit is contained in:
1 parent
2eadc722e9
commit
ac278065d2
3 files changed
+12
-4
No files matched your search
@@ -1,3 +1,4 @@
|
|||||||
|
FLASK_ENV=production
|
||||||
SECRET_KEY=replace-this-with-a-long-random-string
|
SECRET_KEY=replace-this-with-a-long-random-string
|
||||||
DATABASE_URL=postgresql+psycopg://user:password@host/dbname
|
DATABASE_URL=postgresql+psycopg://user:password@host/dbname
|
||||||
APP_BASE_URL=https://myboker.org
|
APP_BASE_URL=https://myboker.org
|
||||||
|
|||||||
@@ -1,11 +1,13 @@
|
|||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
|
import os
|
||||||
|
|
||||||
import click
|
import click
|
||||||
from flask import Flask
|
from flask import Flask
|
||||||
|
|
||||||
from auth import current_user_id, is_logged_in
|
from auth import current_user_id, is_logged_in
|
||||||
from config import Config
|
from config import Config, ProductionConfig
|
||||||
from db import database_extensions_available, db, init_database
|
from db import database_extensions_available, db, init_database
|
||||||
from extensions import csrf, limiter, mail
|
from extensions import csrf, limiter, mail
|
||||||
from routes.account import account_bp
|
from routes.account import account_bp
|
||||||
@@ -17,7 +19,8 @@ from utils import cents_to_dollars, safe_date_label
|
|||||||
|
|
||||||
def create_app(config_overrides: dict | None = None) -> Flask:
|
def create_app(config_overrides: dict | None = None) -> Flask:
|
||||||
app = Flask(__name__)
|
app = Flask(__name__)
|
||||||
app.config.from_object(Config)
|
cfg = ProductionConfig if os.getenv("FLASK_ENV") == "production" else Config
|
||||||
|
app.config.from_object(cfg)
|
||||||
if config_overrides:
|
if config_overrides:
|
||||||
app.config.update(config_overrides)
|
app.config.update(config_overrides)
|
||||||
|
|
||||||
@@ -60,4 +63,4 @@ def create_app(config_overrides: dict | None = None) -> Flask:
|
|||||||
app = create_app()
|
app = create_app()
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
app.run(debug=True)
|
app.run(debug=os.getenv("FLASK_DEBUG", "0") == "1")
|
||||||
+5
-1
@@ -1,6 +1,8 @@
|
|||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
|
from urllib.parse import urlparse
|
||||||
|
|
||||||
from flask import Blueprint, flash, redirect, render_template, request, url_for
|
from flask import Blueprint, flash, redirect, render_template, request, url_for
|
||||||
|
|
||||||
from auth import (
|
from auth import (
|
||||||
@@ -97,7 +99,9 @@ def login():
|
|||||||
flash("That account is disabled.", "error")
|
flash("That account is disabled.", "error")
|
||||||
else:
|
else:
|
||||||
log_user_in(user.id)
|
log_user_in(user.id)
|
||||||
next_url = request.args.get("next") or url_for("leagues.index")
|
raw_next = request.args.get("next", "")
|
||||||
|
parsed = urlparse(raw_next)
|
||||||
|
next_url = raw_next if (raw_next and not parsed.netloc and not parsed.scheme) else url_for("leagues.index")
|
||||||
flash("Logged in.", "success")
|
flash("Logged in.", "success")
|
||||||
return redirect(next_url)
|
return redirect(next_url)
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user