Skip to content
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

Do not pin SID to a specific IP address #1786

Merged
merged 3 commits into from
Dec 13, 2023
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
10 changes: 3 additions & 7 deletions src/api/auth.c
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,6 @@ int check_client_auth(struct ftl_conn *api, const bool is_api)
{
if(auth_data[i].used &&
auth_data[i].valid_until >= now &&
strcmp(auth_data[i].remote_addr, api->request->remote_addr) == 0 &&
strcmp(auth_data[i].sid, sid) == 0)
{
if(need_csrf && strcmp(auth_data[i].csrf, csrf) != 0)
Expand All @@ -217,10 +216,7 @@ int check_client_auth(struct ftl_conn *api, const bool is_api)
}
if(user_id > API_AUTH_UNAUTHORIZED)
{
// Authentication successful:
// - We know this client
// - The session is (still) valid
// - The IP matches the one we know for this SID
// Authentication successful: valid session

// Update timestamp of this client to extend
// the validity of their API authentication
Expand All @@ -245,8 +241,8 @@ int check_client_auth(struct ftl_conn *api, const bool is_api)
{
char timestr[128];
get_timestr(timestr, auth_data[user_id].valid_until, false, false);
log_debug(DEBUG_API, "Recognized known user: user_id %i, valid_until: %s, remote_addr %s",
user_id, timestr, auth_data[user_id].remote_addr);
log_debug(DEBUG_API, "Recognized known user: user_id %i, valid_until: %s, remote_addr %s (%s at login)",
user_id, timestr, api->request->remote_addr, auth_data[user_id].remote_addr);
}
}
else
Expand Down
6 changes: 5 additions & 1 deletion src/api/docs/content/specs/auth.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,11 @@ components:
operationId: "add_auth"
security: []
description: |
Login with a password. The password is not stored in the session, and neither when to generating the session token.
Authenticate using a password. The password isn't stored in the session nor used to create the session token. Instead, the session token is produced using a cryptographically secure random number generator. A CSRF token is utilized to guard against CSRF attacks and is necessary when using Cookie-based authentication. However, it's not needed with other authentication methods.

Both the Session ID (SID) and CSRF token remain valid for the session's duration. The session can be extended before its expiration by performing any authenticated action. By default, the session lasts for 5 minutes. It can be invalidated by either logging out or deleting the session. Additionally, the session becomes invalid when the password is altered or a new application password is created.

If two-factor authentication (2FA) is activated, the Time-based One-Time Password (TOTP) token must be included in the request body. Be aware that the TOTP token, generated by your authenticator app, is only valid for 30 seconds. If the TOTP token is missing, invalid, or has been used previously, the login attempt will be unsuccessful.
requestBody:
description: Callback payload
content:
Expand Down