Skip to content

Commit

Permalink
Fix long password validation in WebServer (#7676)
Browse files Browse the repository at this point in the history
Use a base64 encode that doesn't add CRs to the output when comparing
username:password values for authentication.

Fixes #7664
  • Loading branch information
earlephilhower committed Oct 25, 2020
1 parent 8d2f53d commit c656266
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions libraries/ESP8266WebServer/src/ESP8266WebServer-impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include "WiFiClient.h"
#include "ESP8266WebServer.h"
#include "FS.h"
#include "base64.h"
#include "detail/RequestHandlersImpl.h"

static const char AUTHORIZATION_HEADER[] PROGMEM = "Authorization";
Expand Down Expand Up @@ -98,21 +99,19 @@ bool ESP8266WebServerTemplate<ServerType>::authenticate(const char * username, c
authReq = "";
return false;
}
char *encoded = new (std::nothrow) char[base64_encode_expected_len(toencodeLen)+1];
if(encoded == NULL){
sprintf(toencode, "%s:%s", username, password);
String encoded = base64::encode((uint8_t *)toencode, toencodeLen, false);
if(!encoded){
authReq = "";
delete[] toencode;
return false;
}
sprintf(toencode, "%s:%s", username, password);
if(base64_encode_chars(toencode, toencodeLen, encoded) > 0 && authReq.equalsConstantTime(encoded)) {
if(authReq.equalsConstantTime(encoded)) {
authReq = "";
delete[] toencode;
delete[] encoded;
return true;
}
delete[] toencode;
delete[] encoded;
} else if(authReq.startsWith(F("Digest"))) {
String _realm = _extractParam(authReq, F("realm=\""));
String _H1 = credentialHash((String)username,_realm,(String)password);
Expand Down

0 comments on commit c656266

Please sign in to comment.