httpd: harden MI/HTTP interface with safe default and Basic Auth#3851
Open
dondetir wants to merge 1 commit intoOpenSIPS:masterfrom
Open
httpd: harden MI/HTTP interface with safe default and Basic Auth#3851dondetir wants to merge 1 commit intoOpenSIPS:masterfrom
dondetir wants to merge 1 commit intoOpenSIPS:masterfrom
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This addresses #2939 by implementing the two hardening steps discussed in the issue:
Step A — Safe default binding (immediate fix)
Change the default
ipmodparam from wildcard (0.0.0.0/::) to127.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 on127.0.0.1:5060while 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 accessauth_password— required password for HTTP accessWhen both
auth_usernameandauth_passwordare configured, every HTTP request must present valid Basic Auth credentials. Unauthenticated or incorrectly authenticated requests receive a 401 Unauthorized response.Implementation notes
MHD_basic_auth_get_username_password/MHD_queue_basic_auth_fail_response).MHD_free()(available since 0.9.56), falling back tofree()on older library versions.Testing
-Wall -Wextra -Werror, zero warnings