Skip to content
12 changes: 12 additions & 0 deletions wled00/set.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -607,6 +607,14 @@ void handleSettingsSet(AsyncWebServerRequest *request, byte subPage)
}
}

// Check if any OTA-related settings are being changed
bool otaSettingsChanged = (request->hasArg(F("NO")) != otaLock) ||
(request->hasArg(F("OW")) != wifiLock) ||
#ifndef WLED_DISABLE_OTA
(request->hasArg(F("AO")) != aOtaEnabled) ||
#endif
(request->hasArg(F("SU")) != otaSameSubnet);

if (pwdCorrect) //allow changes if correct pwd or no ota active
{
otaLock = request->hasArg(F("NO"));
Expand All @@ -615,6 +623,10 @@ void handleSettingsSet(AsyncWebServerRequest *request, byte subPage)
aOtaEnabled = request->hasArg(F("AO"));
#endif
otaSameSubnet = request->hasArg(F("SU"));
} else if (otaLock && otaSettingsChanged) {
// If OTA is locked and password is incorrect AND user tried to change OTA settings, return error immediately
serveMessage(request, 401, F("Error"), F("Password incorrect"), 254);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we're going to fail out a request, this must be checked and handled before any other operations are performed. Otherwise the user could be surprised by a request being "partially handled".

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in commit 5760385. Password validation is now checked at the beginning of the handler, before any other operations are performed. This prevents partial saves where PIN might be updated but OTA settings fail.

return;
}
}

Expand Down