Skip to content

Commit bda7b11

Browse files
committed
web_server: Bypass local authorization if authorized via remote access
Don't request athorization for any requests arriving via an address that belongs to a valid remote access connection. Remote access connections can only be established after a successful remote access login. Also properly return any system errors from auth callbacks/functions.
1 parent 900a8b6 commit bda7b11

File tree

2 files changed

+19
-5
lines changed

2 files changed

+19
-5
lines changed

software/src/modules/web_server/module.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ Optional = Debug
1111
Watchdog
1212
Certs
1313
WS
14+
Remote Access
1415

1516
[Options]
1617
web_server_http_enabled = 1

software/src/modules/web_server/web_server.cpp

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -390,12 +390,25 @@ esp_err_t WebServer::low_level_handler(httpd_req_t *req)
390390
auto request = WebServerRequest{req};
391391

392392
if (server->auth_fn && !server->auth_fn(request)) {
393-
if (server->on_not_authorized) {
394-
server->on_not_authorized(request);
395-
return ESP_OK;
393+
bool auth_by_remote_access = false;
394+
395+
#if MODULE_REMOTE_ACCESS_AVAILABLE()
396+
const IPAddress local_address = request.getLocalAddress();
397+
398+
// If this times out, it will probably unpredictably overwrite something on the stack.
399+
task_scheduler.await([&local_address, &auth_by_remote_access]() {
400+
auth_by_remote_access = remote_access.is_connected_local_ip(local_address);
401+
});
402+
#endif
403+
404+
if (!auth_by_remote_access) {
405+
if (server->on_not_authorized) {
406+
const WebServerRequestReturnProtect ret = server->on_not_authorized(request);
407+
return ret.error;
408+
}
409+
const WebServerRequestReturnProtect ret = request.requestAuthentication();
410+
return ret.error;
396411
}
397-
request.requestAuthentication();
398-
return ESP_OK;
399412
}
400413

401414
const struct httpd_req_aux *aux = static_cast<struct httpd_req_aux *>(req->aux);

0 commit comments

Comments
 (0)