Skip to content

Commit a187022

Browse files
committed
Validate auth_token during startup
1 parent 4db9974 commit a187022

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

pyfilebrowser/main.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
from types import FrameType
1212
from typing import List, Optional
1313

14+
import pyotp
1415
import yaml
1516

1617
from pyfilebrowser.modals import models, settings
@@ -212,10 +213,13 @@ def create_config(self) -> None:
212213
)
213214
self.logger.debug("Extra settings - %s: %s", key, value)
214215
final_settings[key].update(value)
215-
# Move the authenticator token to the expected location
216-
final_settings["auther"][
217-
"authenticator_token"
218-
] = self.env.config_settings.auther.token
216+
# Move the authenticator token to the expected location, if token is valid
217+
if self.env.config_settings.auther.token:
218+
totp = pyotp.TOTP(self.env.config_settings.auther.token)
219+
assert totp.verify(totp.now(), for_time=time.time()), "Invalid auth_token!"
220+
final_settings["auther"][
221+
"authenticator_token"
222+
] = self.env.config_settings.auther.token
219223
final_settings["auther"].pop("token")
220224
# Remove symlinks from the final settings
221225
final_settings["server"].pop("symlinks")

0 commit comments

Comments
 (0)