stuartpittaway / diyBMSv4ESP32

diyBMS v4 code for the ESP32 and new controller hardware
Other
186 stars 81 forks source link

Using the "Save Rules" on the rules page results in "Failed to save settings" #149

Closed cons0l3 closed 1 year ago

cons0l3 commented 2 years ago

Hi Stuart et al.,

first of all, great work. Thanks! I will put something into the cookie jar.

When trying to save changed rule parameters, I receive a "Failed to save settings" (POST /post/saverules) returns a 400 with an "Invalid cookie" in the response. All other "Save"-operations work great. So I compared the POST of eg. /post/saventp request header with the header for /post/saverules. Everything important e.g. Cookie looks exactly the same.

I have identified the function "validateXSSWithPOST" and checked if the "xss" parameter in the request body (form-data) is properly set. It is in all requests. Its value equals the Cookie.

The ESP-LOG puts out a W (12468745) diybms-webfuncs: xss query key returned not OK, which implies that httpd_query_key_value(postbuffer, "xss", param, sizeof(param)) == ESP_OK is not ok.

I found the $.ajaxPrefilter function in pagecode.js which injects the xss-parameter in every POST request. Looks fine.

Why does this work for all the other posts, but not the /post/saverules? My debug-capabilities are reading the source code. Your setup propably allows debugging into a running ESP32.

Could you please look into it. Or tell me to clear my browser cache, which I have already tried ;.) Thanks.

I run an esp32, Controller with HW-version c8f1403, Cellmodules v4.4 (HW-version 09be325).

The software version of the controller...

Platform & Version
Host name:[DIYBMS-009DBDD8](http://diybms-009dbdd8/)
Processor: ESP32
Version: [4d240d0120df636fbe0bf136d1db2aa3e0a35694](https://github.com/stuartpittaway/diyBMSv4ESP32/commit/4d240d0120df636fbe0bf136d1db2aa3e0a35694)
Compiled: 2022-09-06T10:32:56.505Z
Language: en
SDK Version:v4.4.1-1-gb8050b365e
Min free Heap:80164
Free heap:112948
Heap size:293280
stuartpittaway commented 2 years ago

I fixed this issue only yesterday! It's not in the master branch though, it's in the pylontech branch, where I'm currently making a lot of changes

cons0l3 commented 1 year ago

Thanks Stuart, I will setup "pio" and compile and burn the pylontech branch.

cons0l3 commented 1 year ago

Hi Stuart, I have successfully compiled and uploaded (commit #6a2dba39afed4312efc57b9bd509085ad3716c79 from branch pylonbatteryemulation). I will close the issue, and re-test after it has been merged with master.