mirror of
https://github.com/esp8266/Arduino.git
synced 2025-04-19 23:22:16 +03:00
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
This commit is contained in:
parent
8d2f53d9a2
commit
c65626622a
@ -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";
|
||||
@ -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);
|
||||
|
Loading…
x
Reference in New Issue
Block a user