Skip to content
Draft
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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ rm "$prod" && ln -s "$old" "$prod"
- `disable_warning_days`: list of day numbers when a user will get an email warning that their account will be disabled
- `disable_day`: day number when a user will be disabled
- a "day number" starts counting from the last day that a user logged in, so on day 5, the user last logged in 5 days ago
- `[api]keys` can now be specified in the config file

### 1.5 -> 1.6

Expand Down
3 changes: 3 additions & 0 deletions defaults/config.ini.default
Original file line number Diff line number Diff line change
Expand Up @@ -132,3 +132,6 @@ disable_warning_days[] = 360
disable_warning_days[] = 380
disable_warning_days[] = 399
disable_day = 400

[api]
keys[] = insert_key_here ; API keys for admin/api/...
12 changes: 12 additions & 0 deletions resources/lib/UnityHTTPD.php
Original file line number Diff line number Diff line change
Expand Up @@ -420,4 +420,16 @@ public static function getCSRFTokenHiddenFormInput(): string
$token = htmlspecialchars(CSRFToken::generate());
return "<input type='hidden' name='csrf_token' value='$token'>";
}

public static function validateAPIKey(): void
{
$authorization = $_SERVER["HTTP_AUTHORIZATION"] ?? "";
if (!str_starts_with($authorization, "Bearer ")) {
self::badRequest("HTTP_AUTHORIZATION is not Bearer", "invalid HTTP_AUTHORIZATION");
}
$key = substr($authorization, strlen("Bearer "));
if (!in_array($key, CONFIG["api"]["keys"])) {
self::forbidden("API key not found in config", "forbidden");
}
}
}