Skip to content

Commit 2ad5fce

Browse files
committed
PR review feedback on port
1 parent d303341 commit 2ad5fce

File tree

3 files changed

+18
-8
lines changed

3 files changed

+18
-8
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -479,7 +479,7 @@ By default, the SonarQube MCP Server uses stdio transport for communication. You
479479
| Environment variable | Description | Default |
480480
|----------------------|--------------------------------------------------------------------------------------------------|-----------------|
481481
| `SONARQUBE_HTTP_ENABLED` | Enable HTTP transport mode instead of stdio. Set to `true` to enable HTTP mode. | `false` |
482-
| `SONARQUBE_HTTP_PORT` | Port number for HTTP server when HTTP transport is enabled (1-65535). | `8080` |
482+
| `SONARQUBE_HTTP_PORT` | Port number for HTTP server when HTTP transport is enabled (1024-65535, unprivileged ports only). | `8080` |
483483
| `SONARQUBE_HTTP_HOST` | Host address to bind HTTP server to. Use `127.0.0.1` for localhost only, `0.0.0.0` for all interfaces. | `127.0.0.1` |
484484

485485
#### Security

src/main/java/org/sonarsource/sonarqube/mcp/configuration/McpServerLaunchConfiguration.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -197,8 +197,8 @@ private static int parseHttpPortValue(@Nullable String portStr) {
197197
}
198198
try {
199199
var port = Integer.parseInt(portStr);
200-
if (port < 1 || port > 65535) {
201-
throw new IllegalArgumentException("SONARQUBE_HTTP_PORT value must be between 1 and 65535, got: " + port);
200+
if (port < 1024 || port > 65535) {
201+
throw new IllegalArgumentException("SONARQUBE_HTTP_PORT value must be between 1024 and 65535 (unprivileged ports only), got: " + port);
202202
}
203203
return port;
204204
} catch (NumberFormatException e) {

src/test/java/org/sonarsource/sonarqube/mcp/configuration/McpServerLaunchConfigurationHttpTest.java

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -133,21 +133,31 @@ void should_handle_blank_http_port_with_default() {
133133
@Test
134134
void should_validate_http_port_bounds_minimum() {
135135
var environment = createMinimalTestEnvironment();
136-
environment.put("SONARQUBE_HTTP_PORT", "0");
136+
environment.put("SONARQUBE_HTTP_PORT", "1023");
137137

138138
assertThatThrownBy(() -> new McpServerLaunchConfiguration(environment))
139139
.isInstanceOf(IllegalArgumentException.class)
140-
.hasMessage("SONARQUBE_HTTP_PORT value must be between 1 and 65535, got: 0");
140+
.hasMessage("SONARQUBE_HTTP_PORT value must be between 1024 and 65535 (unprivileged ports only), got: 1023");
141+
}
142+
143+
@Test
144+
void should_reject_privileged_ports() {
145+
var environment = createMinimalTestEnvironment();
146+
environment.put("SONARQUBE_HTTP_PORT", "80");
147+
148+
assertThatThrownBy(() -> new McpServerLaunchConfiguration(environment))
149+
.isInstanceOf(IllegalArgumentException.class)
150+
.hasMessageContaining("SONARQUBE_HTTP_PORT value must be between 1024 and 65535 (unprivileged ports only)");
141151
}
142152

143153
@Test
144154
void should_accept_valid_http_port_bounds() {
145155
var environment = createMinimalTestEnvironment();
146156

147-
// Test minimum valid port
148-
environment.put("SONARQUBE_HTTP_PORT", "1");
157+
// Test minimum valid unprivileged port
158+
environment.put("SONARQUBE_HTTP_PORT", "1024");
149159
var config1 = new McpServerLaunchConfiguration(environment);
150-
assertThat(config1.getHttpPort()).isEqualTo(1);
160+
assertThat(config1.getHttpPort()).isEqualTo(1024);
151161

152162
// Test maximum valid port
153163
environment.put("SONARQUBE_HTTP_PORT", "65535");

0 commit comments

Comments
 (0)