Skip to content

Commit af8dd55

Browse files
Security fixes
Refactor URL safety check and cleanup unused function and removed debug mode running Signed-off-by: Shahm Najeeb <Nirt_12023@outlook.com>
1 parent 5462f5d commit af8dd55

File tree

3 files changed

+8
-24
lines changed

3 files changed

+8
-24
lines changed

README.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,6 @@ This project is ready to deploy on [Vercel](https://vercel.com) with just a few
9292
- No need to configure anything manually except ENV VARIABLES:
9393
- `SECRET_KEY`: Flask Secret Key - Make this strong
9494
- `DATABASE_URL`: Postgresql access URL - I recommend AIVEN
95-
- `FLASK_ENV`: `production` or `development`, production is the default and is more secure using waitress to serve the application, SECURITY RISK
9695

9796
5. **Deploy!**
9897
- Wait for the build to finish
@@ -116,11 +115,15 @@ This project is ready to deploy on [Vercel](https://vercel.com) with just a few
116115
```bash
117116
pip install -r requirements.txt
118117
```
119-
3. **Start the application**
118+
3. **Set up the ENV variables**
119+
- `SECRET_KEY`: Flask Secret Key - Make this strong
120+
- `DATABASE_URL`: Postgresql access URL - I recommend AIVEN
121+
122+
4. **Start the application**
120123
```bash
121124
python app.py
122125
```
123-
4. **Access the application**
126+
5. **Access the application**
124127
Open your browser and navigate to `http://localhost:5000`
125128

126129
#### First-time Setup

app.py

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import uuid
66
from datetime import datetime, UTC
77
from functools import wraps
8-
from urllib.parse import urlparse, urljoin
8+
from urllib.parse import urlparse
99

1010
import psutil
1111
import psycopg2
@@ -21,8 +21,6 @@
2121
# Configuration
2222
app.config["SECRET_KEY"] = os.environ.get("SECRET_KEY", "EMPTY")
2323
db_url = os.environ.get("DATABASE_URL", "EMPTY")
24-
# Options: production or development
25-
RELEASE_TYPE = os.environ.get('RELEASE_TYPE', 'production')
2624

2725
# We advise to keep this FALSE as it may undermine security and put too much pressure on servers if set to True, admins bypass this
2826
# Allow access to the endpoint if (overridden if ALLOW_PUBLIC_API_ACCESS = True):
@@ -401,12 +399,6 @@ class SqlQueryForm(Form):
401399

402400

403401
# Security Helpers
404-
def is_safe_url(target):
405-
ref_url = urlparse(request.host_url)
406-
test_url = urlparse(urljoin(request.host_url, target))
407-
return test_url.scheme in ('http', 'https') and ref_url.netloc == test_url.netloc
408-
409-
410402
def get_client_ip():
411403
if request.headers.getlist("X-Forwarded-For"):
412404
return request.headers.getlist("X-Forwarded-For")[0]
@@ -755,11 +747,6 @@ def login():
755747
session['admin'] = True
756748

757749
create_log("Login", f"User {wallet_name} logged in", "Admin")
758-
759-
# Redirect to a safe URL
760-
next_page = request.args.get('next')
761-
if next_page and is_safe_url(next_page):
762-
return redirect(next_page)
763750
return redirect(url_for('home'))
764751

765752
return render_template('login.html', error="Invalid credentials")
@@ -2435,7 +2422,4 @@ def initialize_database():
24352422

24362423

24372424
if __name__ == '__main__':
2438-
if RELEASE_TYPE == 'production':
2439-
serve(app, host='0.0.0.0', port=5000)
2440-
else:
2441-
app.run(ssl_context='adhoc', debug=True, port=5000)
2425+
serve(app, host='0.0.0.0', port=5000)

templates/setup.html

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,6 @@ <h5 class="mb-0">Initialize Bank System</h5>
3838
<ul class="mb-0 mt-2">
3939
<li><code>SECRET_KEY</code>: Flask Secret Key</li>
4040
<li><code>DATABASE_URL</code>: Postgresql access URL</li>
41-
<li><code>FLASK_ENV</code>: <code>production</code> or <code>development</code>, production
42-
is the default and is more secure using waitress to serve the application
43-
</li>
4441
</ul>
4542
</div>
4643
</div>

0 commit comments

Comments
 (0)