Skip to content

Add check for localhost auth #518

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Dec 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion tests/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

def test_config():
# Defaults
default_bind = "0.0.0.0:80"
default_bind = "127.0.0.1:8080"
set_config([], {})
assert config.bind == default_bind
assert config.datadir == "~/_timetagger"
Expand Down
7 changes: 6 additions & 1 deletion timetagger/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,12 @@ async def get_webtoken_localhost(request, auth_info):
"""An authentication handler that provides a webtoken when the
hostname is localhost. See `get_webtoken_unsafe()` for details.
"""

if not config.bind.startswith("127.0.0.1"):
return (
403,
{},
"Can only login via localhost if the server address (config.bind) is '127.0.0.1'",
)
# Don't allow localhost validation when proxy auth is enabled
if config.proxy_auth_enabled:
return 403, {}, "forbidden: disabled when proxy auth is available"
Expand Down
4 changes: 2 additions & 2 deletions timetagger/_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def to_bool(value):
class Config:
"""Object that holds config values.

* `bind (str)`: the address and port to bind on. Default "0.0.0.0:80".
* `bind (str)`: the address and port to bind on. Default "127.0.0.1:8080".
* `datadir (str)`: the directory to store data. Default "~/_timetagger".
The user db's are stored in `datadir/users`.
* `log_level (str)`: the log level for timetagger and asgineer
Expand Down Expand Up @@ -43,7 +43,7 @@ class Config:
"""

_ITEMS = [
("bind", str, "0.0.0.0:80"),
("bind", str, "127.0.0.1:8080"),
("datadir", str, "~/_timetagger"),
("log_level", str, "info"),
("credentials", str, ""),
Expand Down
Loading