espressif / arduino-esp32

Arduino core for the ESP32
GNU Lesser General Public License v2.1
13.49k stars 7.38k forks source link

Cookie jar can't work with session cookies #9830

Open OldGraff opened 4 months ago

OldGraff commented 4 months ago

Board

ESP32 Dev Module

Device Description

ESP32-DevKitC-32E Chip Model:ESP32-D0WD-V3, revision:3

Hardware Configuration

Plain board connected to AP

Version

v2.0.16

IDE Name

PlatformIO

Operating System

Windows 10

Flash frequency

40Mhz

PSRAM enabled

no

Upload speed

115200

Description

Cookie jar can't work with session cookies because it doesn't have property expires and max-age and default value is zero https://github.com/espressif/arduino-esp32/blob/575a415719d875f88460ec1461408597744f7053/libraries/HTTPClient/src/HTTPClient.h#L163 When we get next cookie previous is erased because cookie.max_age.duration <= 0 condition is always true https://github.com/espressif/arduino-esp32/blob/575a415719d875f88460ec1461408597744f7053/libraries/HTTPClient/src/HTTPClient.cpp#L1581-L1584 I suggest changing comparison in condition to a non-strict cookie.max_age.duration < 0 or change default value in struct Cookie

Also cookie string concatenation not working properly because space is before ; symbol and should be after semicolon https://github.com/espressif/arduino-esp32/blob/575a415719d875f88460ec1461408597744f7053/libraries/HTTPClient/src/HTTPClient.cpp#L1616 Should I create for cookie concatenation string bug another issue?

Sketch

#include <Arduino.h>
#include <HTTPClient.h>
#include <WiFiSecureClient/WiFiSecureClient.h>

const char *hostPtr = "https://examle.com";  // Server URL

CookieJar cookieJar;
HTTPClient https;

void sendDataForm() {
  client.setCACert(someRootCACertificate);

  https.setReuse(true);
  https.setCookieJar(&cookieJar);

  https.begin(client, hostPtr);

  // Specify content-type header
  https.addHeader("Content-Type", "application/x-www-form-urlencoded"); 

  // Send HTTP POST request
  https.POST(authFormData + hiddenInputName + "=1");

  https.end();
}

Debug Message

I don't know what I should write here

Other Steps to Reproduce

No response

I have checked existing issues, online documentation and the Troubleshooting Guide

VojtechBartoska commented 1 month ago

Hello @OldGraff,

networking was refactored for version 3.0.0.

Will you be able to retest your sketch with 3.1.0-RC1?

Thanks a lot!