Skip to content

Security: Missing input validation for repository names and URLs #3

@sfloess

Description

@sfloess

Security Issue - HIGH Priority

Description

The NexusClient and Credentials classes do not validate or sanitize repository names and URLs before constructing HTTP requests. This could lead to URL injection attacks or malformed requests.

Locations

  1. src/main/java/org/flossware/jnexus/NexusClient.java lines 157-163
  2. src/main/java/org/flossware/jnexus/Credentials.java line 156

Evidence

// No validation of repository parameter
String url = baseUrl + "/service/rest/v1/components?repository=" + repository;

// No URL format validation
if (url == null || url.isBlank()) {
    throw new IllegalStateException("Nexus URL not configured...");
}

Security Impact

  • Potential for URL injection attacks
  • Malformed URLs could cause unexpected behavior
  • No sanitization of user input before HTTP requests
  • Could expose internal network information

Attack Scenarios

  1. Repository name with special characters: repo&malicious=param
  2. Repository name with path traversal: ../../admin
  3. Invalid URL formats leading to crashes or information disclosure

Recommendations

  1. Validate repository names against allowed character set (alphanumeric, dash, underscore)
  2. Validate URL format using URI parsing
  3. URL-encode repository names before concatenation
  4. Add input sanitization at service layer
  5. Reject URLs with suspicious patterns

Implementation

private void validateRepository(String repository) {
    if (repository == null || repository.isBlank()) {
        throw new IllegalArgumentException("Repository cannot be null or blank");
    }
    if (!repository.matches("[a-zA-Z0-9_-]+")) {
        throw new IllegalArgumentException("Repository contains invalid characters");
    }
}

private void validateUrl(String url) {
    try {
        URI uri = URI.create(url);
        if (!uri.getScheme().equals("https") && !uri.getScheme().equals("http")) {
            throw new IllegalArgumentException("URL must use HTTP or HTTPS");
        }
    } catch (Exception e) {
        throw new IllegalArgumentException("Invalid URL format", e);
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions