Skip to content

Commit c656266

Browse files
Fix long password validation in WebServer (#7676)
Use a base64 encode that doesn't add CRs to the output when comparing username:password values for authentication. Fixes #7664
1 parent 8d2f53d commit c656266

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

libraries/ESP8266WebServer/src/ESP8266WebServer-impl.h

+5-6
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include "WiFiClient.h"
2727
#include "ESP8266WebServer.h"
2828
#include "FS.h"
29+
#include "base64.h"
2930
#include "detail/RequestHandlersImpl.h"
3031

3132
static const char AUTHORIZATION_HEADER[] PROGMEM = "Authorization";
@@ -98,21 +99,19 @@ bool ESP8266WebServerTemplate<ServerType>::authenticate(const char * username, c
9899
authReq = "";
99100
return false;
100101
}
101-
char *encoded = new (std::nothrow) char[base64_encode_expected_len(toencodeLen)+1];
102-
if(encoded == NULL){
102+
sprintf(toencode, "%s:%s", username, password);
103+
String encoded = base64::encode((uint8_t *)toencode, toencodeLen, false);
104+
if(!encoded){
103105
authReq = "";
104106
delete[] toencode;
105107
return false;
106108
}
107-
sprintf(toencode, "%s:%s", username, password);
108-
if(base64_encode_chars(toencode, toencodeLen, encoded) > 0 && authReq.equalsConstantTime(encoded)) {
109+
if(authReq.equalsConstantTime(encoded)) {
109110
authReq = "";
110111
delete[] toencode;
111-
delete[] encoded;
112112
return true;
113113
}
114114
delete[] toencode;
115-
delete[] encoded;
116115
} else if(authReq.startsWith(F("Digest"))) {
117116
String _realm = _extractParam(authReq, F("realm=\""));
118117
String _H1 = credentialHash((String)username,_realm,(String)password);

0 commit comments

Comments
 (0)