Skip to content

Bug audit fixes for dev preview#65

Open
ODevStudio wants to merge 8 commits into
decentespresso:mainfrom
ODevStudio:bug-audit-fixes-clean
Open

Bug audit fixes for dev preview#65
ODevStudio wants to merge 8 commits into
decentespresso:mainfrom
ODevStudio:bug-audit-fixes-clean

Conversation

@ODevStudio
Copy link
Copy Markdown
Collaborator

Collects the current bug-audit fixes for a dev preview/tester build.

Scope:

  • Firmware hardening for WebSocket,
    BLE/USB protocol bounds,
    WiFi setup/recovery,
    OTA callback handling,
    EEPROM persistence, and quick-boot status reporting.
  • Web app fixes for command bindings,
    WebSocket parsing guards,
    CSP, preset parsing,
    and invalid weight handling.

@tadelv tadelv self-requested a review June 5, 2026 13:57
Copy link
Copy Markdown
Collaborator

@tadelv tadelv left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

some comments inline. I get the need to sanitize and guard for edge cases, but the work could be split in (at least) half if the packing/unpacking would be unified, it seems.

Comment thread platformio.ini Outdated
#board_build.partitions = <min_spiffs.csv>
board_build.filesystem = littlefs
monitor_speed = 115200
upload_port = COM3
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do not specify upload ports this way, some users might have steam hardware on that port, or even have linux port designation

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reverted the platformio.ini

Comment thread platformio.ini Outdated
; growth; complements the WS_BROADCAST_HEAP_FLOOR gate in include/websocket.h.
-D WS_MAX_QUEUED_MESSAGES=8
!python3 git_rev_macro.py
!python git_rev_macro.py
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

absolutely sure about this one? keep in mind most important is the github action can run

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reverted the platformio.ini

async _enableNotification() {
await this.readCharacteristic.startNotifications();
this.readCharacteristic.addEventListener('characteristicvaluechanged', this.notification_handler.bind(this));
this.readCharacteristic.addEventListener('characteristicvaluechanged', this.notificationHandler);
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

are the characteristics used in the hosted version of Weigh_Save?
I believe websocket should be used to get weight data

Copy link
Copy Markdown
Collaborator Author

@ODevStudio ODevStudio Jun 5, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes: when Weigh_Save is served from the scale over HTTP, live weight comes from /snapshot WebSocket. The BLE characteristics are only for direct browser-to-scale connection support.

const ws = new ReconnectingWebSocket(ws://${window.location.host}/snapshot);
...
if (jsondata.grams !== undefined) {
const weight = Number(jsondata.grams);
...
ui.updateWeightDisplay(currentWeight);
scale.processWeight(currentWeight);
}

Comment thread include/websocket.h
if (mask & WSP_TIMER_STOP) { stopWatch.stop(); }
if (mask & WSP_TIMER_ZERO) { stopWatch.reset(); }
if (mask & WSP_SET_SAMPLES) {
scale.setSamplesInUse(samplesInUse);
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

which task is this call coming from, the main or the websocket task? possible race?
just want to be sure.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

scale.setSamplesInUse() runs from the main loop via the pending queue, not directly from the WebSocket task

Comment thread include/webserver.h Outdated
String pass = jsonObj["pass"];

saveCredentials(ssid, pass);
saveCredentialsForRestart(ssid, pass);
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not forward error from nvs save to api response?

Comment thread include/usbcomm.h
void sendUsbGyro();
#endif

static inline uint16_t encodeScaledUInt16(float value, float scale) {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we have encode in multiple places if i see this correctly. can we unify the command parsing as well as data serialization for ble and usb?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, there is some duplication in the encode helpers. That would need BLE/USB protocol-helper cleanup as a separate follow-up, with testing.

Comment thread include/usbcomm.h
return false;
}

uint8_t calculatePayloadChecksum(uint8_t *data, size_t len) {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same for checksum, my knowledge about the source might be poor, but we could simplify instead of have duplicates (if we actually have duplicates)

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also for the checksum there are duplications. i keep that in mind

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants