Skip to content

Commit

Permalink
Merge pull request #7 from Private-Net-work/hotfix/password_hashing_a…
Browse files Browse the repository at this point in the history
…lgorithm

Vulnerable hashing methods fixed
  • Loading branch information
Nikita Aksenov authored Sep 7, 2022
2 parents cc2f420 + cb3287b commit 116c4ce
Show file tree
Hide file tree
Showing 7 changed files with 10 additions and 20 deletions.
5 changes: 2 additions & 3 deletions blueprints/auth.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import hashlib
from werkzeug.security import generate_password_hash, check_password_hash
from secrets import compare_digest

from flask import Blueprint, request, current_app, make_response
Expand All @@ -15,8 +15,7 @@ def is_admin():
def auth():
if request.method == "POST":
password = request.form["password"]
if compare_digest(hashlib.sha512(bytes(password, encoding='utf-8')).digest().hex(),
current_app.config["ADMIN_PASSWORD"]):
if check_password_hash(current_app.config["ADMIN_PASSWORD"], password):
response = make_response("You have logged in successfully!")
response.set_cookie("auth", current_app.config["AUTH_COOKIE"],
max_age=3600 * 24 * 365 * 100, secure=True)
Expand Down
1 change: 0 additions & 1 deletion blueprints/notes.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
from data.notes import Note

notes_bp = Blueprint("notes", "notes")
SYMBOLS = list("qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM1234567890")


@notes_bp.route('/', methods=["GET", "POST"])
Expand Down
12 changes: 4 additions & 8 deletions modules/logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,30 +63,26 @@ def before_request():


def after_request(response):
ip = request.headers.get("Cf-Connecting-Ip", None)
ip_hash = hashlib.sha512(ip.encode()).hexdigest()[:15] if ip else "NoIp"
path = request.full_path[:-1] if request.full_path[-1] == "?" else request.full_path
status_type = int(str(response.status_code)[0])
country = request.headers.get("Cf-Ipcountry", "NoCountry")
referer = request.headers.get("Referer", "NoReferer")
modified = request.headers.get("If-Modified-Since", "NoIfModif")
if ip_hash == "NoIp":
ip_hash = request.remote_addr
if path.startswith("/static"):
logger.debug('%s %s %s %s %s %s %s Referer: %s IfModif: %s', ip_hash, country, request.method,
logger.debug('%s %s %s %s %s %s Referer: %s IfModif: %s', country, request.method,
request.scheme,
request.host, path, response.status, referer, modified)
else:
if status_type == 5:
logger.error('%s %s %s %s %s %s %s Referer: %s IfModif: %s', ip_hash, country, request.method,
logger.error('%s %s %s %s %s %s Referer: %s IfModif: %s', country, request.method,
request.scheme,
request.host, path, response.status, referer, modified)
elif status_type == 4:
logger.warning('%s %s %s %s %s %s %s Referer: %s IfModif: %s', ip_hash, country, request.method,
logger.warning('%s %s %s %s %s %s Referer: %s IfModif: %s', country, request.method,
request.scheme,
request.host, path, response.status, referer, modified)
else:
logger.info('%s %s %s %s %s %s %s Referer: %s IfModif: %s', ip_hash, country, request.method,
logger.info('%s %s %s %s %s %s Referer: %s IfModif: %s', country, request.method,
request.scheme,
request.host, path, response.status, referer, modified)

Expand Down
Binary file modified translations/en/LC_MESSAGES/messages.mo
Binary file not shown.
4 changes: 1 addition & 3 deletions translations/en/LC_MESSAGES/messages.po
Original file line number Diff line number Diff line change
Expand Up @@ -310,9 +310,7 @@ msgstr ""
"ip-addresses <abbr title=\"Hash — function, that 'encrypts' a "
"string without possible decryption. Equal strings have equal hashes. "
"That's why using ip hashes we can distinguish different visitors, but "
"can't get their IPs.\">hashes</abbr> to distinguish different site"
" visitors, which can be helpful, while we debug. These hashes are also"
" used in our antispam systems. </p>"
"can't get their IPs.\">hashes</abbr> that are used in our antispam systems.</p>"

#: templates/disposable_notes/about_notes.jinja2:224
msgid "faq stats"
Expand Down
Binary file modified translations/ru/LC_MESSAGES/messages.mo
Binary file not shown.
8 changes: 3 additions & 5 deletions translations/ru/LC_MESSAGES/messages.po
Original file line number Diff line number Diff line change
Expand Up @@ -321,14 +321,12 @@ msgid "faq storing-ip"
msgstr ""
"<p> Мы стараемся не собирать информацию о своих посетителях. "
"Ip-адрес — это тоже информация о посетителе, по которой можно его "
"идентифицировать. Поэтому в своих основных журналах запросов к сайту"
" мы храним только <abbr title='Хеш — функция, которая "
"идентифицировать. Поэтому в своих журналах запросов к сайту"
" мы не храним только <abbr title='Хеш — функция, которая "
"позволяет \"зашифровать\" строку без возможности расшифровки. Одинаковые "
"строки имеют одинаковые значения хешей. Поэтому, используя хеш ip-адреса,"
" мы можем понять, где он был одинаковый, а где — разный, но не можем "
"узнать сам ip-адрес.'>хеш</abbr> от ip-адреса, чтобы отличать "
"разных посетителей, когда мы осуществляем поиск ошибок в работе "
"нашего сайта. Ещё хеш ip-адреса используеся в наших "
"узнать сам ip-адрес.'>хеш</abbr> от ip-адреса, который используеся в наших "
"антиспам-системах для защиты от ботов и злоумышленников, которые иногда "
"пытаются создавать записки в неограниченных количествах. </p>"

Expand Down

0 comments on commit 116c4ce

Please sign in to comment.