Skip to content

Commit 9a6c388

Browse files
committed
do options unauthenticated first, fix testing localhost
1 parent 40cb0aa commit 9a6c388

File tree

1 file changed

+8
-9
lines changed

1 file changed

+8
-9
lines changed

supervisor/shared/web_workflow/web_workflow.c

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -375,11 +375,10 @@ static bool _origin_ok(const char *origin) {
375375
return true;
376376
}
377377

378-
// Port or no port
379378
const char *localhost = "127.0.0.1";
380-
const int locallen = 9;
381-
if (memcmp(origin + strlen(http), localhost, locallen) == 0
382-
&& (localhost[locallen] == '\0' || localhost[locallen] == ':')) {
379+
end = origin + strlen(http) + strlen(localhost);
380+
if (memcmp(origin + strlen(http), localhost, strlen(localhost)) == 0
381+
&& (end[0] == '\0' || end[0] == ':')) {
383382
return true;
384383
}
385384

@@ -913,8 +912,10 @@ static bool _reply(socketpool_socket_obj_t *socket, _request *request) {
913912
ESP_LOGE(TAG, "bad origin %s", request->origin);
914913
_reply_forbidden(socket, request);
915914
} else if (memcmp(request->path, "/fs/", 4) == 0) {
916-
// OPTIONS is sent for CORS preflight, unauthenticated
917-
if (!request->authenticated && strcmp(request->method, "OPTIONS") != 0) {
915+
if (strcmp(request->method, "OPTIONS") == 0) {
916+
// OPTIONS is sent for CORS preflight, unauthenticated
917+
_reply_access_control(socket, request);
918+
} else if (!request->authenticated) {
918919
if (_api_password[0] != '\0') {
919920
_reply_unauthorized(socket, request);
920921
} else {
@@ -935,9 +936,7 @@ static bool _reply(socketpool_socket_obj_t *socket, _request *request) {
935936
}
936937
// Delete is almost identical for files and directories so share the
937938
// implementation.
938-
if (strcmp(request->method, "OPTIONS") == 0) {
939-
_reply_access_control(socket, request);
940-
} else if (strcmp(request->method, "DELETE") == 0) {
939+
if (strcmp(request->method, "DELETE") == 0) {
941940
if (_usb_active()) {
942941
_reply_conflict(socket, request);
943942
return false;

0 commit comments

Comments
 (0)