Skip to content

httpd: harden MI/HTTP interface with safe default and Basic Auth#3851

Merged
bogdan-iancu merged 1 commit intoOpenSIPS:masterfrom
dondetir:feature/mi-http-security-hardening
Apr 7, 2026
Merged

httpd: harden MI/HTTP interface with safe default and Basic Auth#3851
bogdan-iancu merged 1 commit intoOpenSIPS:masterfrom
dondetir:feature/mi-http-security-hardening

Conversation

@dondetir
Copy link
Copy Markdown
Contributor

Summary

This addresses #2939 by implementing the two hardening steps discussed in the issue:

Step A — Safe default binding (immediate fix)

Change the default ip modparam from wildcard (0.0.0.0/::) to 127.0.0.1, preventing the management interface from being accidentally exposed to the network on fresh installations. As noted in the issue, the residential helper script sets SIP to listen on 127.0.0.1:5060 while httpd defaults to all interfaces — this inconsistency is now resolved.

Step B — HTTP Basic Authentication

Add three new modparams to the httpd module:

  • auth_realm — realm string for WWW-Authenticate challenges (default: "OpenSIPS MI")
  • auth_username — required username for HTTP access
  • auth_password — required password for HTTP access

When both auth_username and auth_password are configured, every HTTP request must present valid Basic Auth credentials. Unauthenticated or incorrectly authenticated requests receive a 401 Unauthorized response.

Implementation notes

  • The authentication check runs once per request on the first MHD callback invocation, before allocating per-request state, avoiding redundant checks on subsequent callbacks during POST processing.
  • Uses libmicrohttpd's built-in Basic Auth API (MHD_basic_auth_get_username_password / MHD_queue_basic_auth_fail_response).
  • Includes version guards for MHD_free() (available since 0.9.56), falling back to free() on older library versions.
  • Empty username is rejected at startup.
  • Documentation updated for all new parameters, including a warning to enable TLS when using Basic Auth.

Testing

  • Builds clean with -Wall -Wextra -Werror, zero warnings
  • All 2545 unit tests pass
  • Runtime verified: 401 without credentials, 401 with wrong credentials, 200 with correct credentials
  • Confirmed httpd binds to loopback only with the new default

Change the default 'ip' modparam from wildcard (0.0.0.0/::) to
127.0.0.1, preventing the management interface from being accidentally
exposed to the network on fresh installations.

Add HTTP Basic Authentication support via three new modparams:
  - auth_realm: the realm string for WWW-Authenticate challenges
  - auth_username: required username for HTTP access
  - auth_password: required password for HTTP access

When both auth_username and auth_password are set, every HTTP
request must present valid Basic Auth credentials.  Requests with
missing or incorrect credentials receive a 401 Unauthorized response.

The authentication check runs once per request (on the first callback
invocation, before allocating per-request state), avoiding redundant
checks on subsequent MHD callbacks and preventing potential resource
leaks during POST processing.

The implementation uses libmicrohttpd's built-in Basic Auth API with
version guards for MHD_free() (available since 0.9.56), falling back
to free() on older versions.

Closes OpenSIPS#2939
@bogdan-iancu
Copy link
Copy Markdown
Member

@dondetir , this looks great, I will merge it now, thank you

@bogdan-iancu bogdan-iancu merged commit 9efaa7a into OpenSIPS:master Apr 7, 2026
@bogdan-iancu bogdan-iancu added this to the 4.0.0 milestone Apr 7, 2026
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.

2 participants