Skip to content

Harden WebServer listener and ReadBody#356

Merged
josesimoes merged 1 commit into
mainfrom
harden-readbody-listener
May 18, 2026
Merged

Harden WebServer listener and ReadBody#356
josesimoes merged 1 commit into
mainfrom
harden-readbody-listener

Conversation

@josesimoes
Copy link
Copy Markdown
Member

@josesimoes josesimoes commented May 15, 2026

Description

  • Add guards against zero/overflow content-lengths and catches all exceptions in ReadBody(). Teturning null instead of propagating to the caller.
  • Wrap StartListner code with try catch blocks.
  • Each request thread now also catches unhandled exceptions and returns 500.
  • Fix IntelliSense comment in ReadBody.

Motivation and Context

  • A SocketException from GetContext() was propagating out of StartListener, killing the accept loop on transient captive-portal probe resets.
  • Issues found when debugging a captive portal project.
  • Bottom line, these changes were added to harden code and make more robust, so the server doesn't crash.

How Has This Been Tested?

  • Local project running smoothly.

Screenshots

Types of changes

  • Improvement (non-breaking change that improves a feature, code or algorithm)
  • Bug fix (non-breaking change which fixes an issue with code or algorithm)
  • New feature (non-breaking change which adds functionality to code)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Config and build (change in the configuration and build system, has no impact on code or features)
  • Dependencies (update dependencies and changes associated, has no impact on code or features)
  • Unit Tests (add new Unit Test(s) or improved existing one(s), has no impact on code or features)
  • Documentation (changes or updates in the documentation, has no impact on code or features)

Checklist:

  • My code follows the code style of this project (only if there are changes in source code).
  • My changes require an update to the documentation (there are changes that require the docs website to be updated).
  • I have updated the documentation accordingly (the changes require an update on the docs in this repo).
  • I have read the CONTRIBUTING document.
  • I have tested everything locally and all new and existing tests passed (only if there are changes in source code).
  • I have added new tests to cover my changes.

- Add guards against zero/overflow content-lengths and catches all
exceptions in ReadBody(). Teturning null instead of propagating to the caller.
- Wrap StartListner code with try catch blocks.
- Each request thread now also catches unhandled exceptions and returns 500.
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 15, 2026

Warning

Rate limit exceeded

@josesimoes has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 59 minutes and 24 seconds before requesting another review.

You’ve run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository: nanoframework/coderabbit/.coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: 8468f6ae-81df-49c1-927c-6cd70ae6452b

📥 Commits

Reviewing files that changed from the base of the PR and between 3f2fc68 and 7e431c3.

📒 Files selected for processing (2)
  • nanoFramework.WebServer/HttpListenerRequestExtensions.cs
  • nanoFramework.WebServer/WebServer.cs

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@sonarqubecloud
Copy link
Copy Markdown

Copy link
Copy Markdown
Member

@Ellerbach Ellerbach left a comment

Choose a reason for hiding this comment

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

Looks good overall. I supposed you've been testing it properly with at least one of the collection and check if all is ok?

@josesimoes
Copy link
Copy Markdown
Member Author

@coderabbitai review

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 18, 2026

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@josesimoes
Copy link
Copy Markdown
Member Author

Looks good overall. I supposed you've been testing it properly with at least one of the collection and check if all is ok?

Yes! Testing this in the context of that captive portal project.

@josesimoes josesimoes merged commit e4e4fa1 into main May 18, 2026
8 checks passed
@josesimoes josesimoes deleted the harden-readbody-listener branch May 18, 2026 10:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants