Skip to content

Add configurable outbound host validation#13866

Open
JanithaSampathBandara wants to merge 3 commits into
wso2:masterfrom
JanithaSampathBandara:remote-host-validation
Open

Add configurable outbound host validation#13866
JanithaSampathBandara wants to merge 3 commits into
wso2:masterfrom
JanithaSampathBandara:remote-host-validation

Conversation

@JanithaSampathBandara

Copy link
Copy Markdown

Description

API Manager performs outbound network requests using user-provided URLs across several features, including:

  • OpenAPI URL imports
  • AsyncAPI URL imports
  • WSDL URL imports
  • GraphQL schema URL imports
  • API endpoint validation
  • API endpoint creation and updates
  • Key Manager discovery and endpoint configuration
  • MCP server creation and updates
  • Backend endpoint configuration

These outbound requests may access destinations outside the control of the API Manager runtime. This improvement introduces centralized outbound network access control and destination validation for user-provided URLs.

Goals

  • Provide centralized validation for user-provided URLs
  • Support platform-level network access control policies
  • Support tenant-level network access control policies
  • Support optional private network access restrictions
  • Maintain backward compatibility when no configuration is present
  • Provide consistent validation behavior across supported URL validation flows

Approach

Platform-Level Configuration

Network access control can be configured using:

[apim.network_security.access_control]
mode = "allow"
hosts = ["api.github.com", "*.wso2.com"]
block_private_network_access = true

Platform administrators can:

  • Restrict outbound access using allow mode
  • Block destinations using deny mode
  • Restrict access to private network ranges
  • Define platform-wide destination restrictions

Platform-level validation is always evaluated before tenant-level validation.

Tenant-Level Configuration

Introduced optional tenant-level network access control through tenant configuration.

{
  "NetworkSecurityAccessControl": {
    "Mode": "allow",
    "Hosts": [
      "*.allowed.example.com"
    ],
    "BlockPrivateNetworkAccess": true
  }
}

Behavior:

  • Tenant-level validation is applied only when configured
  • Platform-level restrictions always take precedence
  • Tenant configuration cannot override platform restrictions

Validation Behavior

  • Allow mode uses the configured hosts list as an allowlist
  • Deny mode uses the configured hosts list as a denylist
  • Optional private network restrictions can be enabled
  • Host matching is performed against the request host and resolved destination addresses
  • Invalid or unresolved destinations are rejected when validation cannot be completed

Covered Validation Entry Points

The following endpoints are protected by this implementation:

  • POST /api/am/publisher/v4/mcp-servers/validate-endpoint
  • POST /api/am/publisher/v4/mcp-servers/validate-mcp-server
  • POST /api/am/publisher/v4/mcp-servers/validate-endpoint
  • POST /api/am/admin/v4/key-managers/discover
  • POST /api/am/admin/v4/key-managers
  • PUT /api/am/admin/v4/key-managers/{keyManagerId}
  • POST /api/am/publisher/v4/mcp-servers/generate-from-mcp-server
  • POST /api/am/publisher/v4/apis/import-graphql-schema
  • PUT /api/am/publisher/v4/apis/{apiId}/swagger
  • POST /api/am/publisher/v4/apis/validate-wsdl
  • POST /api/am/publisher/v4/apis/import-wsdl
  • POST /api/am/publisher/v4/apis/validate-openapi
  • POST /api/am/publisher/v4/mcp-servers/validate-openapi
  • POST /api/am/publisher/v4/apis/import-openapi
  • POST /api/am/publisher/v4/apis/validate-graphql-schema
  • POST /api/am/publisher/v4/apis/validate-asyncapi
  • POST /api/am/publisher/v4/mcp-servers/import
  • POST /api/am/publisher/v4/apis/import-asyncapi
  • POST /api/am/publisher/v4/mcp-servers/generate-from-openapi
  • POST /api/am/publisher/v4/apis/{apiId}/endpoints
  • PUT /api/am/publisher/v4/apis/{apiId}/endpoints/{endpointId}
  • PUT /api/am/publisher/v4/mcp-servers/{mcpServerId}/backends/{backendId}
  • POST /api/am/publisher/v4/apis
  • PUT /api/am/publisher/v4/apis/{apiId}
  • PUT /api/am/publisher/v4/apis/{apiId}/asyncapi
  • PUT /api/am/publisher/v4/apis/{apiId}/wsdl
  • POST /api/am/publisher/v4/mcp-servers/generate-from-api
  • PUT /api/am/publisher/v4/mcp-servers/{mcpServerId}
  • POST /api/am/publisher/v4/apis/import

Error Handling

Client validation failures:

HTTP 400: The provided URL is not trusted. Please contact the system administrator.

Configuration issues:

HTTP 500: Internal server error. Please contact the system administrator.

Detailed diagnostics remain available in server logs.

Testing

Added and updated coverage for:

  • Platform allow mode validation
  • Platform deny mode validation
  • Tenant access control validation
  • Private network access restrictions
  • Configuration precedence validation

Backward Compatibility

When network access control configuration is not present, existing behavior remains unchanged.

@CLAassistant

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.


JanithaSampathBandara seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account.
You have signed the CLA already but the status is still pending? Let us recheck it.

@coderabbitai

coderabbitai Bot commented Jun 8, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 8c2a0aeb-62de-4e38-8547-7fffa99427c1

📥 Commits

Reviewing files that changed from the base of the PR and between a02c8c5 and df8e9b2.

📒 Files selected for processing (5)
  • components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/utils/APIUtil.java
  • components/apimgt/org.wso2.carbon.apimgt.impl/src/main/resources/tenant/tenant-config-schema.json
  • components/apimgt/org.wso2.carbon.apimgt.rest.api.admin.v1/src/main/java/org/wso2/carbon/apimgt/rest/api/admin/v1/impl/KeyManagersApiServiceImpl.java
  • components/apimgt/org.wso2.carbon.apimgt.rest.api.publisher.v1.common/src/main/java/org/wso2/carbon/apimgt/rest/api/publisher/v1/common/mappings/PublisherCommonUtils.java
  • components/apimgt/org.wso2.carbon.apimgt.rest.api.publisher.v1.common/src/test/java/org/wso2/carbon/apimgt/rest/api/publisher/v1/common/mappings/PublisherCommonUtilsTest.java
🚧 Files skipped from review as they are similar to previous changes (4)
  • components/apimgt/org.wso2.carbon.apimgt.impl/src/main/resources/tenant/tenant-config-schema.json
  • components/apimgt/org.wso2.carbon.apimgt.rest.api.publisher.v1.common/src/test/java/org/wso2/carbon/apimgt/rest/api/publisher/v1/common/mappings/PublisherCommonUtilsTest.java
  • components/apimgt/org.wso2.carbon.apimgt.rest.api.admin.v1/src/main/java/org/wso2/carbon/apimgt/rest/api/admin/v1/impl/KeyManagersApiServiceImpl.java
  • components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/utils/APIUtil.java

📝 Walkthrough

Walkthrough

Adds tenant-scoped NetworkSecurityAccessControl: schema and constants, central APIUtil.validateRemoteURL with host/IP checks, new exception codes, and integrates outbound URL validation across Key Managers, API imports (WSDL/GraphQL/AsyncAPI), MCP servers, publisher import utilities, tests, and templates.

Changes

Network Security Access Control Feature

Layer / File(s) Summary
Core network security framework
components/apimgt/org.wso2.carbon.apimgt.api/src/main/java/org/wso2/carbon/apimgt/api/ExceptionCodes.java, components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/APIConstants.java, components/apimgt/org.wso2.carbon.apimgt.impl/src/main/resources/tenant/tenant-config-schema.json, components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/utils/APIUtil.java
Adds UNTRUSTED_URL and NETWORK_SECURITY_ACCESS_CONTROL_MISCONFIGURED exception codes; introduces NetworkSecurityAccessControl constants and tenant-config schema; implements APIUtil.validateRemoteURL(...), extractURLsFromEndpointConfig(...), config fields, init wiring, hostname wildcard matching, DNS resolution, and private/reserved IP detection (including IPv6 ULA).
Key Manager URL validation
components/apimgt/org.wso2.carbon.apimgt.rest.api.admin.v1/src/main/java/org/wso2/carbon/apimgt/rest/api/admin/v1/impl/KeyManagersApiServiceImpl.java
Validates discovery and configured Key Manager endpoint URLs (standard fields, custom endpoints, JWKS cert URL) via APIUtil prior to persisting, converting 400 validation results into field-specific bad requests.
API import & definition validation
components/apimgt/org.wso2.carbon.apimgt.rest.api.publisher.v1/src/main/java/org/wso2/carbon/apimgt/rest/api/publisher/v1/impl/ApisApiServiceImpl.java
Integrates remote URL validation for WSDL/GraphQL/AsyncAPI imports and validation flows: validates definition source URLs and endpointConfig-extracted endpoints; maps HTTP 400 validation failures to bad requests and other failures to internal-server errors where applicable.
Import utilities & publisher validators
components/apimgt/org.wso2.carbon.apimgt.rest.api.publisher.v1.common/src/main/java/.../ImportUtils.java, PublisherCommonUtils.java, RestApiPublisherUtils.java
Extracts production/sandbox and failover endpoints from endpointConfig maps and validates each URL tenant-scoped via APIUtil; replaces legacy boolean checks with tenant-aware validateRemoteURL calls; adds OpenAPI URL validation with 400-to-bad-request mapping.
MCP server validation integration
components/apimgt/org.wso2.carbon.apimgt.rest.api.publisher.v1/src/main/java/.../McpServersApiServiceImpl.java
Validates MCP proxy and backend endpoint URLs before import/update; rewrites endpoint-config parsing to JSON object paths and validates extracted endpoints and failovers tenant-scoped; maps 400 validation failures into DTO error fields for endpoint HEAD validation.
Tests and configuration template
components/apimgt/org.wso2.carbon.apimgt.rest.api.publisher.v1.common/src/test/java/.../PublisherCommonUtilsTest.java, features/apimgt/.../api-manager.xml.j2
Updates tests to mock tenant domain retrieval for endpoint validation; adds Jinja template section to render NetworkSecurityAccessControl configuration in api-manager.xml.j2.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

Possibly related PRs

  • wso2/carbon-apimgt#13846: Modifies MCP server import backend handling; overlaps with this PR's edits to importMCPServer and related MCP import/update logic.

Suggested reviewers

  • AnuGayan
  • chamilaadhi
  • dushaniw
  • pubudu538
  • tgtshanika
  • Arshardh
  • HiranyaKavishani
  • hisanhunais
  • senthuran16
  • RakhithaRR
  • HeshanSudarshana
  • npamudika
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 44.44% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title 'Add configurable outbound host validation' clearly and concisely describes the main change: introducing configurable network access control for outbound URL validation across multiple API Manager features.
Description check ✅ Passed The description is comprehensive and directly related to the changeset, explaining the motivation, goals, platform/tenant-level configuration approaches, validation behavior, covered endpoints, error handling, testing, and backward compatibility.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ast-grep (0.43.0)
components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/utils/APIUtil.java
components/apimgt/org.wso2.carbon.apimgt.rest.api.publisher.v1.common/src/main/java/org/wso2/carbon/apimgt/rest/api/publisher/v1/common/mappings/PublisherCommonUtils.java

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.

@wso2-engineering wso2-engineering Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

AI Agent Log Improvement Checklist

⚠️ Warning: AI-Generated Review Comments

  • The log-related comments and suggestions in this review were generated by an AI tool to assist with identifying potential improvements. Purpose of reviewing the code for log improvements is to improve the troubleshooting capabilities of our products.
  • Please make sure to manually review and validate all suggestions before applying any changes. Not every code suggestion would make sense or add value to our purpose. Therefore, you have the freedom to decide which of the suggestions are helpful.

✅ Before merging this pull request:

  • Review all AI-generated comments for accuracy and relevance.
  • Complete and verify the table below. We need your feedback to measure the accuracy of these suggestions and the value they add. If you are rejecting a certain code suggestion, please mention the reason briefly in the suggestion for us to capture it.
Comment Accepted (Y/N) Reason
#### Log Improvement Suggestion No: 1
#### Log Improvement Suggestion No: 2
#### Log Improvement Suggestion No: 3
#### Log Improvement Suggestion No: 4
#### Log Improvement Suggestion No: 5
#### Log Improvement Suggestion No: 6
#### Log Improvement Suggestion No: 7
#### Log Improvement Suggestion No: 8
#### Log Improvement Suggestion No: 9
#### Log Improvement Suggestion No: 10
#### Log Improvement Suggestion No: 11
#### Log Improvement Suggestion No: 12
#### Log Improvement Suggestion No: 13
#### Log Improvement Suggestion No: 14

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 12

🧹 Nitpick comments (2)
components/apimgt/org.wso2.carbon.apimgt.api/src/main/java/org/wso2/carbon/apimgt/api/ExceptionCodes.java (1)

147-149: 💤 Low value

Differentiate error message and description for consistency.

The errorMessage and errorDescription parameters are identical for NETWORK_SECURITY_ACCESS_CONTROL_MISCONFIGURED. Throughout this file, the convention is to use a brief label for errorMessage and a more detailed explanation for errorDescription. Consider updating to match this pattern.

Suggested improvement
 NETWORK_SECURITY_ACCESS_CONTROL_MISCONFIGURED(900406,
-        "Internal server error. Please contact the system administrator.", 500,
-        "Internal server error. Please contact the system administrator."),
+        "Network security access control misconfigured", 500,
+        "Internal server error. Please contact the system administrator."),
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In
`@components/apimgt/org.wso2.carbon.apimgt.api/src/main/java/org/wso2/carbon/apimgt/api/ExceptionCodes.java`
around lines 147 - 149, The enum entry
NETWORK_SECURITY_ACCESS_CONTROL_MISCONFIGURED in ExceptionCodes currently uses
identical strings for errorMessage and errorDescription; change the first
parameter to a concise label (e.g., "Network security access control
misconfigured" or "Network access control misconfigured") and keep the second
parameter as the detailed user-facing explanation (retain the longer "Internal
server error. Please contact the system administrator." or replace with a more
specific description), ensuring the signature of
NETWORK_SECURITY_ACCESS_CONTROL_MISCONFIGURED(...) remains unchanged.
components/apimgt/org.wso2.carbon.apimgt.rest.api.publisher.v1.common/src/main/java/org/wso2/carbon/apimgt/rest/api/publisher/v1/common/mappings/ImportUtils.java (1)

344-355: ⚡ Quick win

Extract endpoint URL trust-validation into a shared helper.

The same extraction/validation block is duplicated in three places (Lines 344-355, 844-855, 917-928). A single helper would keep behavior consistent and prevent drift in security validation logic.

Refactor sketch
+    private static void validateEndpointURLs(org.json.JSONObject endpointConfigObj, String tenantDomain)
+            throws APIManagementException {
+        if (APIConstants.ENDPOINT_TYPE_DEFAULT.equalsIgnoreCase(
+                endpointConfigObj.optString(APIConstants.API_ENDPOINT_CONFIG_PROTOCOL_TYPE))) {
+            return;
+        }
+        ArrayList<String> endpointURLs = new ArrayList<>();
+        APIUtil.extractURLsFromEndpointConfig(endpointConfigObj, APIConstants.API_DATA_PRODUCTION_ENDPOINTS,
+                endpointURLs);
+        APIUtil.extractURLsFromEndpointConfig(endpointConfigObj, APIConstants.API_DATA_SANDBOX_ENDPOINTS,
+                endpointURLs);
+        APIUtil.extractURLsFromEndpointConfig(endpointConfigObj, APIConstants.ENDPOINT_PRODUCTION_FAILOVERS,
+                endpointURLs);
+        APIUtil.extractURLsFromEndpointConfig(endpointConfigObj, APIConstants.ENDPOINT_SANDBOX_FAILOVERS,
+                endpointURLs);
+        for (String endpointURL : endpointURLs) {
+            APIUtil.validateRemoteURL(endpointURL, tenantDomain);
+        }
+    }

Also applies to: 844-855, 917-928

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In
`@components/apimgt/org.wso2.carbon.apimgt.rest.api.publisher.v1.common/src/main/java/org/wso2/carbon/apimgt/rest/api/publisher/v1/common/mappings/ImportUtils.java`
around lines 344 - 355, Create a shared helper in ImportUtils (e.g.,
extractAndValidateEndpointURLs or validateEndpointConfigURLs) that takes the
endpointConfigObj and tenantDomain, performs the ArrayList<String> endpointURLs
creation, calls APIUtil.extractURLsFromEndpointConfig for
APIConstants.API_DATA_PRODUCTION_ENDPOINTS,
APIConstants.API_DATA_SANDBOX_ENDPOINTS,
APIConstants.ENDPOINT_PRODUCTION_FAILOVERS and
APIConstants.ENDPOINT_SANDBOX_FAILOVERS, and then iterates calling
APIUtil.validateRemoteURL(endpointURL, tenantDomain); replace the duplicated
blocks at the locations currently using the same extraction/validation logic
(the blocks around the current calls shown using
APIUtil.extractURLsFromEndpointConfig and APIUtil.validateRemoteURL) with a
single call to this new helper to keep validation consistent.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In
`@components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/APIConstants.java`:
- Line 4006: The HOSTS constant in APIConstants currently uses the singular key
value "Host" which mismatches the feature contract/tenant key expecting "Hosts";
update the value of the HOSTS constant (public static final String HOSTS) to use
the plural "Hosts" so it aligns with NetworkSecurityAccessControl/tenant keys
and downstream lookups; after changing the constant value, run a quick search
for references to APIConstants.HOSTS to ensure no callers rely on the old
singular key and update any test/fixture data that asserted the previous string.

In
`@components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/utils/APIUtil.java`:
- Around line 12571-12576: The code in APIUtil currently treats a non-empty
hosts with blank mode as a warn-and-continue (fail-open); change this to surface
as a configuration error: in the same block that checks
StringUtils.isBlank(mode) and sees hosts != null && !hosts.isEmpty(), replace
the silent warn with logging an error and throwing an exception (e.g.,
APIManagementException or IllegalStateException) that contains a clear message
referencing the misconfigured `hosts` + blank `mode`, so callers of APIUtil will
get an HTTP 500 rather than silently ignoring the access-control list.
- Around line 12577-12599: The current early return when isHostInList(host,
hosts) is true bypasses private-network checks; change the logic so that after a
hostname allowlist hit you still call InetAddress.getAllByName(host) and
validate the resolved IPs against the private-network rules before returning: if
blockPrivateNetworkAccess is enabled (or the equivalent flag used elsewhere) and
any resolved IP falls into private ranges (10/8, 172.16/12, 192.168/16,
fc00::/7), throw buildURLBlockedException(host); only return immediately if the
hostname is allowlisted and none of the resolved addresses violate the
private-network restriction. Use the existing isHostInList,
InetAddress.getAllByName, isAnyResolvedIpInList and buildURLBlockedException
symbols to locate and implement the check.
- Around line 12501-12510: validateRemoteURL() incorrectly uses new
URL(url).getHost(), which triggers a MalformedURLException for ws:// or wss://
schemes; instead, change validateRemoteURL() to parse the host without requiring
a URLStreamHandler by using java.net.URI (e.g., new
URI(url).getHost()/getAuthority()) or by delegating to the existing
validateEndpointURL() logic that uses Apache Commons UrlValidator with
ALLOW_ALL_SCHEMES; update the exception mapping so legitimate websocket
endpoints are not classified as MALFORMED_URL and only throw
APIManagementException when URI/UrlValidator indicates a truly invalid endpoint.

In
`@components/apimgt/org.wso2.carbon.apimgt.impl/src/main/resources/tenant/tenant-config-schema.json`:
- Around line 1366-1395: NetworkSecurityAccessControl allows missing or
arbitrary Mode values; update the JSON schema for the
NetworkSecurityAccessControl object to make the "Mode" property required and
restrict its value to the enum ["allow","deny"] (modify the "Mode" subschema to
add an "enum" with those two strings) and add "Mode" to the parent object's
required array so config validation fails for missing/invalid modes; reference
the NetworkSecurityAccessControl object and the "Mode" property in your change.

In
`@components/apimgt/org.wso2.carbon.apimgt.rest.api.admin.v1/src/main/java/org/wso2/carbon/apimgt/rest/api/admin/v1/impl/KeyManagersApiServiceImpl.java`:
- Around line 355-359: In validateKeyManagerURL, stop blindly returning on any
MalformedURLException from new URL(url).getHost(); instead, explicitly check for
the legacy sentinel value(s) (e.g., the exact string "none") and only skip
validation for those; for any other malformed URL, propagate a 400 Bad Request
(e.g., throw the same BadRequestException used elsewhere) so
APIUtil.validateRemoteURL(...) still runs for valid URLs and network/host policy
checks are enforced. Ensure the change is applied inside
KeyManagersApiServiceImpl.validateKeyManagerURL around the new URL(...) call and
that APIUtil.validateRemoteURL(...) is invoked for non-sentinel, well-formed
URLs.

In
`@components/apimgt/org.wso2.carbon.apimgt.rest.api.publisher.v1.common/src/main/java/org/wso2/carbon/apimgt/rest/api/publisher/v1/common/mappings/PublisherCommonUtils.java`:
- Around line 2703-2706: PublisherCommonUtils currently calls
APIUtil.validateRemoteURL unconditionally for each endpoint (using tenantDomain
from RestApiCommonUtil.getLoggedInUserTenantDomain()), which causes non-URL
endpoint styles (e.g., JMS, consul(…), and parameterized endpoints with { }
allowed by validateEndpointURL) to fail; change the loop so
APIUtil.validateRemoteURL is only invoked for real HTTP(S) URLs — skip
validation when the endpoint starts with "jms:" or "consul(" or contains
parameter placeholders ("{" or "}") — keeping the existing tenantDomain usage
and leaving validateEndpointURL behavior intact.

In
`@components/apimgt/org.wso2.carbon.apimgt.rest.api.publisher.v1/src/main/java/org/wso2/carbon/apimgt/rest/api/publisher/v1/impl/ApisApiServiceImpl.java`:
- Line 3208: Replace calls to APIUtil.validateRemoteURL(...,
RestApiCommonUtil.getLoggedInUserTenantDomain()) with the request-scoped
organization from RestApiUtil.getValidatedOrganization(messageContext); locate
each occurrence in ApisApiServiceImpl (e.g., the call shown and the other listed
ranges) and pass RestApiUtil.getValidatedOrganization(messageContext) as the
organization argument instead of
RestApiCommonUtil.getLoggedInUserTenantDomain(), ensuring messageContext is
available in the calling scope (retrieve or add it where needed) so the SSRF
checks use the validated organization for that request.
- Around line 4741-4748: The callers of APIUtil.validateRemoteURL in the
AsyncAPI validate/import/update flows are swallowing client-side 400 errors and
converting them to 500; update each AsyncAPI handler that currently catches
APIManagementException around APIUtil.validateRemoteURL to mirror the GraphQL
handling: inside the catch inspect e.getErrorHandler() and if
getHttpStatusCode()==400 rethrow
RestApiUtil.buildBadRequestException(e.getErrorHandler().getErrorDescription()),
otherwise rethrow or pass through to existing handleInternalServerError logic;
specifically change the catch blocks that surround APIUtil.validateRemoteURL in
the AsyncAPI validate/import/update methods so 400s are preserved as BadRequest
responses instead of becoming internal errors.

In
`@components/apimgt/org.wso2.carbon.apimgt.rest.api.publisher.v1/src/main/java/org/wso2/carbon/apimgt/rest/api/publisher/v1/impl/McpServersApiServiceImpl.java`:
- Line 1008: Calls to APIUtil.validateRemoteURL in McpServersApiServiceImpl are
using RestApiCommonUtil.getLoggedInUserTenantDomain() which enforces the tenant
scope instead of the request-validated organization; update those calls (the
occurrences around APIUtil.validateRemoteURL) to pass
RestApiUtil.getValidatedOrganization(messageContext) as the org parameter
(ensure you import/use RestApiUtil and have access to messageContext) so
validation runs in the correct organization scope.
- Around line 2436-2450: The current conditional around
APIConstants.ENDPOINT_TYPE_DEFAULT prevents validateRemoteURL from running for
default protocol endpoints; remove or alter the if-check so that
APIUtil.validateRemoteURL(...) is invoked for all endpoint URLs extracted from
endpointConfig (including when APIConstants.API_ENDPOINT_CONFIG_PROTOCOL_TYPE
equals APIConstants.ENDPOINT_TYPE_DEFAULT). Locate the block using
endpointConfig and APIConstants.ENDPOINT_TYPE_DEFAULT in
McpServersApiServiceImpl and ensure the code always collects endpoints (via
APIUtil.extractURLsFromEndpointConfig) and calls
APIUtil.validateRemoteURL(endpoint, tenantDomain) for each entry, preserving the
existing extraction of production/sandbox/failover lists.

In
`@components/apimgt/org.wso2.carbon.apimgt.rest.api.publisher.v1/src/main/java/org/wso2/carbon/apimgt/rest/api/publisher/v1/utils/RestApiPublisherUtils.java`:
- Around line 748-751: Replace the tenant domain argument to
APIUtil.validateRemoteURL(...) so it uses the request-scoped organization from
the request context instead of RestApiCommonUtil.getLoggedInUserTenantDomain();
obtain the request organization via the appropriate RestApiCommonUtil
request-context accessor (the request-scoped organization helper provided by
RestApiCommonUtil) and pass that value to APIUtil.validateRemoteURL in this
method and the other occurrences where APIUtil.validateRemoteURL is called
(e.g., the calls referenced around lines 656-657).

---

Nitpick comments:
In
`@components/apimgt/org.wso2.carbon.apimgt.api/src/main/java/org/wso2/carbon/apimgt/api/ExceptionCodes.java`:
- Around line 147-149: The enum entry
NETWORK_SECURITY_ACCESS_CONTROL_MISCONFIGURED in ExceptionCodes currently uses
identical strings for errorMessage and errorDescription; change the first
parameter to a concise label (e.g., "Network security access control
misconfigured" or "Network access control misconfigured") and keep the second
parameter as the detailed user-facing explanation (retain the longer "Internal
server error. Please contact the system administrator." or replace with a more
specific description), ensuring the signature of
NETWORK_SECURITY_ACCESS_CONTROL_MISCONFIGURED(...) remains unchanged.

In
`@components/apimgt/org.wso2.carbon.apimgt.rest.api.publisher.v1.common/src/main/java/org/wso2/carbon/apimgt/rest/api/publisher/v1/common/mappings/ImportUtils.java`:
- Around line 344-355: Create a shared helper in ImportUtils (e.g.,
extractAndValidateEndpointURLs or validateEndpointConfigURLs) that takes the
endpointConfigObj and tenantDomain, performs the ArrayList<String> endpointURLs
creation, calls APIUtil.extractURLsFromEndpointConfig for
APIConstants.API_DATA_PRODUCTION_ENDPOINTS,
APIConstants.API_DATA_SANDBOX_ENDPOINTS,
APIConstants.ENDPOINT_PRODUCTION_FAILOVERS and
APIConstants.ENDPOINT_SANDBOX_FAILOVERS, and then iterates calling
APIUtil.validateRemoteURL(endpointURL, tenantDomain); replace the duplicated
blocks at the locations currently using the same extraction/validation logic
(the blocks around the current calls shown using
APIUtil.extractURLsFromEndpointConfig and APIUtil.validateRemoteURL) with a
single call to this new helper to keep validation consistent.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: b4fe2e25-0b31-4da0-82ca-5b85275ce1c1

📥 Commits

Reviewing files that changed from the base of the PR and between 46921ef and a02c8c5.

📒 Files selected for processing (12)
  • components/apimgt/org.wso2.carbon.apimgt.api/src/main/java/org/wso2/carbon/apimgt/api/ExceptionCodes.java
  • components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/APIConstants.java
  • components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/utils/APIUtil.java
  • components/apimgt/org.wso2.carbon.apimgt.impl/src/main/resources/tenant/tenant-config-schema.json
  • components/apimgt/org.wso2.carbon.apimgt.rest.api.admin.v1/src/main/java/org/wso2/carbon/apimgt/rest/api/admin/v1/impl/KeyManagersApiServiceImpl.java
  • components/apimgt/org.wso2.carbon.apimgt.rest.api.publisher.v1.common/src/main/java/org/wso2/carbon/apimgt/rest/api/publisher/v1/common/mappings/ImportUtils.java
  • components/apimgt/org.wso2.carbon.apimgt.rest.api.publisher.v1.common/src/main/java/org/wso2/carbon/apimgt/rest/api/publisher/v1/common/mappings/PublisherCommonUtils.java
  • components/apimgt/org.wso2.carbon.apimgt.rest.api.publisher.v1.common/src/test/java/org/wso2/carbon/apimgt/rest/api/publisher/v1/common/mappings/PublisherCommonUtilsTest.java
  • components/apimgt/org.wso2.carbon.apimgt.rest.api.publisher.v1/src/main/java/org/wso2/carbon/apimgt/rest/api/publisher/v1/impl/ApisApiServiceImpl.java
  • components/apimgt/org.wso2.carbon.apimgt.rest.api.publisher.v1/src/main/java/org/wso2/carbon/apimgt/rest/api/publisher/v1/impl/McpServersApiServiceImpl.java
  • components/apimgt/org.wso2.carbon.apimgt.rest.api.publisher.v1/src/main/java/org/wso2/carbon/apimgt/rest/api/publisher/v1/utils/RestApiPublisherUtils.java
  • features/apimgt/org.wso2.carbon.apimgt.core.feature/src/main/resources/conf_templates/templates/repository/conf/api-manager.xml.j2

@JanithaSampathBandara

Copy link
Copy Markdown
Author

Reviewed the AI-generated log improvement suggestions and validated them manually.

Comment Accepted (Y/N) Reason
Log Improvement Suggestion No: 1 #13866 (comment) N Adds unnecessary DEBUG/INFO logs.
Log Improvement Suggestion No: 2 #13866 (comment) N Adds unnecessary DEBUG/INFO logs.
Log Improvement Suggestion No: 3 #13866 (comment) N Adds unnecessary DEBUG/INFO logs.
Log Improvement Suggestion No: 4 #13866 (comment) N Adds unnecessary DEBUG/INFO logs.
Log Improvement Suggestion No: 5 #13866 (comment) N Adds unnecessary DEBUG/INFO logs.
Log Improvement Suggestion No: 6 #13866 (comment) N Adds unnecessary DEBUG/INFO logs.
Log Improvement Suggestion No: 7 #13866 (comment) N Adds unnecessary DEBUG/INFO logs.
Log Improvement Suggestion No: 8 #13866 (comment) N Adds unnecessary DEBUG/INFO logs.
Log Improvement Suggestion No: 9 #13866 (comment) N Adds unnecessary DEBUG/INFO logs.
Log Improvement Suggestion No: 10 #13866 (comment) N Adds unnecessary DEBUG/INFO logs.
Log Improvement Suggestion No: 11 #13866 (comment) N Adds unnecessary DEBUG/INFO logs.
Log Improvement Suggestion No: 12 #13866 (comment) N Adds unnecessary DEBUG/INFO logs.
Log Improvement Suggestion No: 13 #13866 (comment) N Adds unnecessary DEBUG/INFO logs.
Log Improvement Suggestion No: 14 #13866 (comment) N Adds unnecessary DEBUG/INFO logs.

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.

2 participants