Skip to content

Add timeout and response size limit for HTTP fetches#86

Merged
campoy merged 2 commits intomasterfrom
fix/http-timeout
Apr 11, 2026
Merged

Add timeout and response size limit for HTTP fetches#86
campoy merged 2 commits intomasterfrom
fix/http-timeout

Conversation

@campoy
Copy link
Copy Markdown
Owner

@campoy campoy commented Apr 11, 2026

Summary

  • Replace the default http.Get (no timeout) with a package-level http.Client set to a 10-second timeout, preventing the process from hanging on slow or unresponsive servers.
  • Wrap the response body with io.LimitReader at 10 MiB so a large response cannot exhaust memory.
  • Add embedmd/content_test.go with three tests using httptest.NewServer:
    • timeout: server hangs after sending headers; expect an error within the short deadline.
    • size limit: server returns more than 10 MiB; expect exactly 10 MiB back with no error.
    • 404: server returns Not Found; expect a non-nil error.

Test plan

  • TestFetchHTTPTimeout — process returns an error when the server stalls
  • TestFetchHTTPSizeLimit — response is capped at exactly 10 MiB
  • TestFetchHTTPNotFound — non-200 status returns an error
  • All existing tests continue to pass (go test ./...)

Closes #81

Francesc Campoy and others added 2 commits April 10, 2026 18:21
Use a package-level http.Client with a 10-second timeout instead of the
default client, and cap response bodies at 10 MiB with io.LimitReader.
This prevents embedmd from hanging indefinitely on slow servers and from
exhausting memory on large responses.

Closes #81
@campoy campoy merged commit d497bcd into master Apr 11, 2026
3 checks passed
@campoy campoy deleted the fix/http-timeout branch April 11, 2026 18:04
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.

HTTP fetch: no timeout or response-size limit allows DoS and SSRF

1 participant