Compare commits

...

7 Commits

Author SHA1 Message Date
copilot-swe-agent[bot]
5760385852 Check password validation before any operations to prevent partial saves
Co-authored-by: willmmiles <6540455+willmmiles@users.noreply.github.com>
2025-12-27 15:21:43 +00:00
copilot-swe-agent[bot]
3e5646d586 Only return 401 when OTA settings are actually being changed
Co-authored-by: DedeHai <6280424+DedeHai@users.noreply.github.com>
2025-12-27 10:57:34 +00:00
copilot-swe-agent[bot]
38b159de86 Return 401 immediately on incorrect password instead of using global flag
Co-authored-by: DedeHai <6280424+DedeHai@users.noreply.github.com>
2025-12-23 18:50:22 +00:00
copilot-swe-agent[bot]
b7485e2ed1 Address PR feedback: invert flag logic to otaPassCorrect, simplify error message, remove leftover file
Co-authored-by: DedeHai <6280424+DedeHai@users.noreply.github.com>
2025-12-23 07:35:49 +00:00
copilot-swe-agent[bot]
92a43ff29a Code review and security check completed
Co-authored-by: DedeHai <6280424+DedeHai@users.noreply.github.com>
2025-12-23 06:09:54 +00:00
copilot-swe-agent[bot]
e9a366e547 Add OTA password validation feedback for security settings
Co-authored-by: DedeHai <6280424+DedeHai@users.noreply.github.com>
2025-12-23 06:05:38 +00:00
copilot-swe-agent[bot]
ce9a8fbaad Initial plan 2025-12-23 05:59:26 +00:00

View File

@@ -580,19 +580,7 @@ void handleSettingsSet(AsyncWebServerRequest *request, byte subPage)
doReboot = true; // may reboot immediately on dual-core system (race condition) which is desireable in this case
}
if (request->hasArg(F("PIN"))) {
const char *pin = request->arg(F("PIN")).c_str();
unsigned pinLen = strlen(pin);
if (pinLen == 4 || pinLen == 0) {
unsigned numZeros = 0;
for (unsigned i = 0; i < pinLen; i++) numZeros += (pin[i] == '0');
if (numZeros < pinLen || pinLen == 0) { // ignore 0000 input (placeholder)
strlcpy(settingsPIN, pin, 5);
}
settingsPIN[4] = 0;
}
}
// Check OTA password validation FIRST before processing any other changes
bool pwdCorrect = !otaLock; //always allow access if ota not locked
if (request->hasArg(F("OP")))
{
@@ -607,6 +595,35 @@ 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 OTA is locked and password is incorrect AND user tried to change OTA settings, return error immediately
// This must be checked BEFORE any other operations to avoid partial saves
if (otaLock && !pwdCorrect && otaSettingsChanged) {
serveMessage(request, 401, F("Error"), F("Password incorrect"), 254);
return;
}
// Now process other settings changes
if (request->hasArg(F("PIN"))) {
const char *pin = request->arg(F("PIN")).c_str();
unsigned pinLen = strlen(pin);
if (pinLen == 4 || pinLen == 0) {
unsigned numZeros = 0;
for (unsigned i = 0; i < pinLen; i++) numZeros += (pin[i] == '0');
if (numZeros < pinLen || pinLen == 0) { // ignore 0000 input (placeholder)
strlcpy(settingsPIN, pin, 5);
}
settingsPIN[4] = 0;
}
}
if (pwdCorrect) //allow changes if correct pwd or no ota active
{
otaLock = request->hasArg(F("NO"));