-
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Return 401 on incorrect OTA password instead of misleading success message #5222
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 3 commits
ce9a8fb
e9a366e
92a43ff
b7485e2
38b159d
3e5646d
5760385
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| . | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -609,12 +609,16 @@ void handleSettingsSet(AsyncWebServerRequest *request, byte subPage) | |
|
|
||
| if (pwdCorrect) //allow changes if correct pwd or no ota active | ||
| { | ||
| otaPasswordIncorrect = false; // clear flag on successful save | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. invert the logic, call it "otaPassCorrect"
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done in commit b7485e2. Renamed flag to |
||
| otaLock = request->hasArg(F("NO")); | ||
| wifiLock = request->hasArg(F("OW")); | ||
| #ifndef WLED_DISABLE_OTA | ||
| aOtaEnabled = request->hasArg(F("AO")); | ||
| #endif | ||
| otaSameSubnet = request->hasArg(F("SU")); | ||
| } else if (otaLock) { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is better, but we should only return failure if any of the OTA-related values have been changed without a correct password. We do not want to return 401s if none of these values were altered. For example, the code as written would generate errors to a user who was enabling a settings PIN, even if they didn't attempt to make any OTA settings changes.
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @copilot please update
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done in commit 3e5646d. Now checks if any OTA-related settings (NO, OW, AO, SU) are being changed before returning a 401 error. Users can modify other security settings (like PIN) without requiring the OTA password when they don't attempt to change OTA settings. |
||
| // If OTA is locked and password is incorrect, flag it | ||
| otaPasswordIncorrect = true; | ||
| } | ||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -753,14 +753,23 @@ void serveSettings(AsyncWebServerRequest* request, bool post) { | |
|
|
||
| char s[32]; | ||
| char s2[45] = ""; | ||
| bool otaPwdErr = otaPasswordIncorrect; // save state before clearing | ||
|
|
||
| switch (subPage) { | ||
| case SUBPAGE_WIFI : strcpy_P(s, PSTR("WiFi")); strcpy_P(s2, PSTR("Please connect to the new IP (if changed)")); break; | ||
| case SUBPAGE_LEDS : strcpy_P(s, PSTR("LED")); break; | ||
| case SUBPAGE_UI : strcpy_P(s, PSTR("UI")); break; | ||
| case SUBPAGE_SYNC : strcpy_P(s, PSTR("Sync")); break; | ||
| case SUBPAGE_TIME : strcpy_P(s, PSTR("Time")); break; | ||
| case SUBPAGE_SEC : strcpy_P(s, PSTR("Security")); if (doReboot) strcpy_P(s2, PSTR("Rebooting, please wait ~10 seconds...")); break; | ||
| case SUBPAGE_SEC : | ||
| strcpy_P(s, PSTR("Security")); | ||
| if (doReboot) strcpy_P(s2, PSTR("Rebooting, please wait ~10 seconds...")); | ||
| else if (otaPwdErr) { | ||
| strcpy_P(s, PSTR("Settings NOT saved!")); | ||
| strcpy_P(s2, PSTR("Incorrect password. Enter correct OTA password to change OTA lock settings.")); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. use "Error" for s and "Password incorect" for s2
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done in commit b7485e2. Changed to "Error" / "Password incorrect". |
||
| otaPasswordIncorrect = false; // clear flag after displaying message | ||
| } | ||
| break; | ||
| #ifdef WLED_ENABLE_DMX | ||
| case SUBPAGE_DMX : strcpy_P(s, PSTR("DMX")); break; | ||
| #endif | ||
|
|
@@ -771,7 +780,7 @@ void serveSettings(AsyncWebServerRequest* request, bool post) { | |
| case SUBPAGE_PINREQ : strcpy_P(s, correctPIN ? PSTR("PIN accepted") : PSTR("PIN rejected")); break; | ||
| } | ||
|
|
||
| if (subPage != SUBPAGE_PINREQ) strcat_P(s, PSTR(" settings saved.")); | ||
| if (subPage != SUBPAGE_PINREQ && !(subPage == SUBPAGE_SEC && otaPwdErr)) strcat_P(s, PSTR(" settings saved.")); | ||
|
|
||
| if (subPage == SUBPAGE_PINREQ && correctPIN) { | ||
| subPage = originalSubPage; // on correct PIN load settings page the user intended | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove this leftover file
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done in commit b7485e2. Removed the leftover symlink.