Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

fix(csrf): Fix SCRF vulnerability in OTA examples and libraries#11530

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
me-no-dev merged 5 commits intomasterfrombugfix/csrf
Jul 2, 2025

Conversation

me-no-dev
Copy link
Member

@me-no-devme-no-dev commentedJun 30, 2025
edited
Loading

@me-no-devme-no-dev requested a review froma team as acode ownerJune 30, 2025 11:26
@github-actionsGitHub Actions
Copy link
Contributor

github-actionsbot commentedJun 30, 2025
edited
Loading

Messages
📖🎉 Good Job! All checks are passing!

👋Hello me-no-dev, we appreciate your contribution to this project!


📘 Please review the project'sContributions Guide for key guidelines on code, documentation, testing, and more.

🖊️ Please also make sure you haveread and signed theContributor License Agreement for this project.

Click to see more instructions ...


This automated output is generated by thePR linter DangerJS, which checks if your Pull Request meets the project's requirements and helps you fix potential issues.

DangerJS is triggered with eachpush event to a Pull Request and modify the contents of this comment.

Please consider the following:
- Danger mainly focuses on the PR structure and formatting and can't understand the meaning behind your code or changes.
- Danger isnot a substitute for human code reviews; it's still important to request a code review from your colleagues.
- To manuallyretry these Danger checks, please navigate to theActions tab and re-run last Danger workflow.

Review and merge process you can expect ...


We do welcome contributions in the form of bug reports, feature requests and pull requests.

1. An internal issue has been created for the PR, we assign it to the relevant engineer.
2. They review the PR and either approve it or ask you for changes or clarifications.
3. Once the GitHub PR is approved we do the final review, collect approvals from core owners and make sure all the automated tests are passing.
- At this point we may do some adjustments to the proposed change, or extend it by adding tests or documentation.
4. If the change is approved and passes the tests it is merged into the default branch.

Generated by 🚫dangerJS againstc94ffcf

@github-actionsGitHub Actions
Copy link
Contributor

github-actionsbot commentedJun 30, 2025
edited
Loading

Memory usage test (comparing PR against master branch)

The table below shows the summary of memory usage change (decrease - increase) in bytes and percentage for each target.

MemoryFLASH [bytes]FLASH [%]RAM [bytes]RAM [%]
TargetDECINCDECINCDECINCDECINC
ESP32P4000.000.00000.000.00
ESP32S3000.000.00000.000.00
ESP32S2000.000.00000.000.00
ESP32C3000.000.00000.000.00
ESP32C6000.000.00000.000.00
ESP32000.000.00000.000.00
Click to expand the detailed deltas report [usage change in BYTES]
TargetESP32P4ESP32S3ESP32S2ESP32C3ESP32C6ESP32
ExampleFLASHRAMFLASHRAMFLASHRAMFLASHRAMFLASHRAMFLASHRAM
libraries/HTTPUpdateServer/examples/WebUpdater------------
libraries/Update/examples/OTAWebUpdater------------
libraries/WebServer/examples/WebUpdate------------

@me-no-dev
Copy link
MemberAuthor

me-no-dev commentedJun 30, 2025
edited
Loading

@JLLeitschuh PTAL

@me-no-devme-no-dev requested a review fromCopilotJune 30, 2025 12:53
Copy link
Contributor

@CopilotCopilotAI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR fixes a CSRF vulnerability by adding authentication and CSRF header checks to OTA update endpoints across various examples.

  • Enforces authentication on update routes
  • Introduces CSRF header collection and validation in multiple files
  • Applies similar security improvements in both WebUpdate and OTA updater code, as well as in the HTTPUpdateServer

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

FileDescription
libraries/WebServer/examples/WebUpdate/WebUpdate.inoAdded authentication and CSRF header validation for OTA updates
libraries/Update/examples/OTAWebUpdater/OTAWebUpdater.inoIntegrated CSRF checks and authentication in OTA update flow
libraries/HTTPUpdateServer/src/HTTPUpdateServer.hUpdated CSRF header collection and verification in the update server
Comments suppressed due to low confidence (3)

libraries/WebServer/examples/WebUpdate/WebUpdate.ino:64

  • Consider adding an inline comment clarifying the CSRF header check logic, explaining the rationale for comparing 'Origin' with 'http://' concatenated with the Host header to improve future maintainability.
          String origin = server.header(String(csrfHeaders[0]));

libraries/Update/examples/OTAWebUpdater/OTAWebUpdater.ino:74

  • Adding an inline comment to document the CSRF validation steps here would help clarify why the origin is compared to 'http://' + host for maintaining secure updates.
    String origin = server.header(String(csrfHeaders[0]));

libraries/HTTPUpdateServer/src/HTTPUpdateServer.h:111

  • Consider sending an explicit HTTP error response (with an appropriate status code) when the CSRF check fails, to clearly communicate the failure to the client.
          String origin = _server->header(String(csrfHeaders[0]));

@me-no-devme-no-dev changed the titlefix(csrf): Fix SCRF vulnerability in WebUpdate.inofix(csrf): Fix SCRF vulnerability in OTA examples and librariesJun 30, 2025
@me-no-devme-no-dev self-assigned thisJun 30, 2025
@github-actionsGitHub Actions
Copy link
Contributor

github-actionsbot commentedJun 30, 2025
edited
Loading

Test Results

 76 files   76 suites   13m 59s ⏱️
 38 tests  38 ✅ 0 💤 0 ❌
241 runs  241 ✅ 0 💤 0 ❌

Results for commitc94ffcf.

♻️ This comment has been updated with latest results.

Copy link

@JLLeitschuhJLLeitschuh left a comment

Choose a reason for hiding this comment

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

This will work, but I'd suggest implementing this as a standard middleware implementation over this solution. That way the logic is reusable. But that's my ten cents. One concern around the use of theHost andOrigin header is that this won't work behind middleware proxies.

That concern is raised here:

Use the Host header value: If you want your application to find its own target so it doesn't have to be configured for each deployed instance, we recommend using the Host family of headers. The Host header is meant to contain the target origin of the request.But, if your app server is sitting behind a proxy, the Host header value is most likely changed by the proxy to the target origin of the URL behind the proxy, which is different than the original URL. This modified Host header origin won't match the source origin in the original Origin or Referer headers.

https://cheatsheetseries.owasp.org/cheatsheets/Cross-Site_Request_Forgery_Prevention_Cheat_Sheet.html?utm_source=chatgpt.com#identifying-the-target-origin

I've more frequently seen CSRF protection implemented via a CSRF token in the form post body, but this will likely also work.

@@ -7,11 +7,16 @@

#define SSID_FORMAT "ESP32-%06lX" // 12 chars total
//#define PASSWORD "test123456" // generate if remarked
const char * authUser = "admin";
const char * authPass = "admin";

Choose a reason for hiding this comment

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

I'd suggest generating a random password that you print to the console to let the user know what it is over using a hard-coded password.

@@ -11,11 +11,16 @@
const char *host = "esp32-webupdate";
const char *ssid = "........";
const char *password = "........";
const char * authUser = "admin";
const char * authPass = "admin";

Choose a reason for hiding this comment

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

Same feedback here. Generate a random password, and serial print it. I would suggest avoiding having this hard-coded in this example

Copy link
MemberAuthor

Choose a reason for hiding this comment

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

I think you are missing the point that this is an Arduino basic example, whose purpose is not to secure every possible scenario, but instead to showcase a particular use (the Updater class). No sane person will useadmin:admin to secure anything. I can put comment to change the default values or define the user/pass as dots (like the SSID and Pass for WiFi), but anything beyond that is over-complication of otherwise basic example that needs to be readable and easy to understand by novice users. Same goes for uses behind proxies, sessions, etc things that are beyond the scope of the examples and whose implementation is not straight-forward on memory constrained devices. Surely feel free to to propose changes in form of Pull Request that will satisfy your requirements :)

UsingHost andOrigin was stated to be enough of a protection by the links in your initial report. Session tokens are not an option in our case at all.

@me-no-devme-no-dev added the Status: Pending MergePull Request is ready to be merged labelJul 2, 2025
@me-no-devme-no-dev merged commitf4fdecc intomasterJul 2, 2025
44 checks passed
@me-no-devme-no-dev deleted the bugfix/csrf branchJuly 2, 2025 11:41
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@JLLeitschuhJLLeitschuhJLLeitschuh left review comments

Copilot code reviewCopilotCopilot left review comments

@P-R-O-C-H-YP-R-O-C-H-YP-R-O-C-H-Y approved these changes

@lucasssvazlucasssvazAwaiting requested review from lucasssvaz

Assignees

@me-no-devme-no-dev

Labels
Status: Pending MergePull Request is ready to be merged
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

3 participants
@me-no-dev@JLLeitschuh@P-R-O-C-H-Y

[8]ページ先頭

©2009-2025 Movatter.jp