Skip to content

Commit

Permalink
Handle trailing slashes correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
rix1337 committed Jan 7, 2023
1 parent 4296f30 commit cb31d97
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 8 deletions.
2 changes: 1 addition & 1 deletion myjd_api/version.py
Expand Up @@ -4,7 +4,7 @@


def get_version():
return "1.0.3"
return "1.0.4"


if __name__ == '__main__':
Expand Down
12 changes: 8 additions & 4 deletions myjd_api/web.py
Expand Up @@ -14,8 +14,7 @@

from Cryptodome.Protocol.KDF import scrypt
from Cryptodome.Random import get_random_bytes
from bottle import Bottle, request, abort, HTTPError

from bottle import Bottle, request, redirect, abort, HTTPError
from myjd_api.common import check_ip
from myjd_api.common import decode_base64
from myjd_api.config import Config
Expand Down Expand Up @@ -103,10 +102,10 @@ def is_authenticated_user(user, password):
auth_user = _config.get('auth_user')
auth_hash = _config.get('auth_hash')
if auth_user and auth_hash:
if auth_hash and "srcypt|" not in auth_hash:
if auth_hash and "scrypt|" not in auth_hash:
salt = get_random_bytes(16).hex()
key = scrypt(auth_hash, salt, 16, N=2 ** 14, r=8, p=1).hex()
auth_hash = "srcypt|" + salt + "|" + key
auth_hash = "scrypt|" + salt + "|" + key
_config.save("auth_hash", to_str(auth_hash))
secrets = auth_hash.split("|")
salt = secrets[1]
Expand Down Expand Up @@ -144,6 +143,11 @@ def myjd_info():
else:
return abort(400, "Failed")

@app.hook('before_request')
def redirect_without_trailing_slash():
if not request.path.endswith('/'):
raise redirect(request.url + '/')

@app.get("/myjd_state/")
@auth_basic(is_authenticated_user)
def myjd_state():
Expand Down
5 changes: 2 additions & 3 deletions requirements.txt
@@ -1,6 +1,5 @@
# -*- coding: utf-8 -*-
# MyJD
# Project by https://github.com/rix1337

bottle==0.12.20
pycryptodomex==3.14.1
bottle==0.12.23
pycryptodomex==3.16.0

0 comments on commit cb31d97

Please sign in to comment.