Exploit database

GH-9a017fa45abc7e1f8f6ba6e1285cae54

iplayforsg/cve-2023-51444

GitHubNot listedPoC
Download repository ZIP

Sources for CVE-2023-51444

1 source

Preferred order: Exploit-DB, Metasploit, then GitHub repositories by stars.

Repository files50

Files from this repository share one source choice. Supporting files may cover other vulnerabilities.

main/src/main/java/org/geoserver/catalog/impl/MetadataLinkInfoImpl.java

Java · 5,154 bytes
/* (c) 2014 Open Source Geospatial Foundation - all rights reserved
 * (c) 2001 - 2013 OpenPlans
 * This code is licensed under the GPL 2.0 license, available at the root
 * application directory.
 */
package org.geoserver.catalog.impl;

import java.net.MalformedURLException;
import java.net.URISyntaxException;
import java.net.URL;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import org.geoserver.catalog.MetadataLinkInfo;

public class MetadataLinkInfoImpl implements MetadataLinkInfo {

    String id;

    String type;

    String about;

    String metadataType;

    String content;

    public MetadataLinkInfoImpl() {
        // nothing to do
    }

    public MetadataLinkInfoImpl(MetadataLinkInfoImpl other) {
        this.id = other.id;
        this.type = other.type;
        this.about = other.about;
        this.metadataType = other.metadataType;
        this.content = other.content;
    }

    @Override
    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    @Override
    public String getAbout() {
        return about;
    }

    @Override
    public void setAbout(String about) {
        this.about = about;
    }

    @Override
    public String getMetadataType() {
        return metadataType;
    }

    @Override
    public void setMetadataType(String metadataType) {
        this.metadataType = metadataType;
    }

    @Override
    public String getType() {
        return type;
    }

    @Override
    public void setType(String type) {
        this.type = type;
    }

    @Override
    public String getContent() {
        return content;
    }

    static final List<String> protocols = new ArrayList<>(Arrays.asList("http", "https", "ftp"));

    /** Adds a value to the list of accepted protocols, meant to be used for testing */
    public static void addProtocol(String protocol) {
        if (!protocols.contains(protocol)) protocols.add(protocol);
    }

    /** @throws IllegalArgumentException if the url is invalid for use as a Metadata Link */
    public static void validate(String url) {
        if (url == null) return;
        URL dummy;
        try {
            dummy = new URL("http://dummy/");
        } catch (MalformedURLException ex) {
            throw new IllegalStateException("Could not parse dummy context URL", ex);
        }
        try {
            // Doing this with exceptions isn't ideal but it works, and we're throwing an
            // exception anyway

            // The dummy context will allow it to parse relative URLs, which should be allowed.
            URL parsed = new URL(dummy, url);
            String protocol = parsed.getProtocol();

            // Converting to URI forces validation
            parsed.toURI();

            if (!protocols.contains(protocol)) {
                throw new IllegalArgumentException(
                        "Protocol " + protocol + " is not supported in url " + url);
            }
        } catch (MalformedURLException | URISyntaxException ex) {
            throw new IllegalArgumentException("Not a valid URL: " + url, ex);
        }
    }

    @Override
    public void setContent(String content) {
        validate(content);
        this.content = content;
    }

    private Object readResolve() {
        validate(content);
        return this;
    }

    @Override
    public int hashCode() {
        final int PRIME = 31;
        int result = 1;
        result = PRIME * result + ((about == null) ? 0 : about.hashCode());
        result = PRIME * result + ((content == null) ? 0 : content.hashCode());
        result = PRIME * result + ((metadataType == null) ? 0 : metadataType.hashCode());
        result = PRIME * result + ((type == null) ? 0 : type.hashCode());
        return result;
    }

    @Override
    public boolean equals(Object obj) {
        if (this == obj) return true;
        if (obj == null) return false;
        if (!(obj instanceof MetadataLinkInfo)) {
            return false;
        }

        final MetadataLinkInfo other = (MetadataLinkInfo) obj;
        if (about == null) {
            if (other.getAbout() != null) return false;
        } else if (!about.equals(other.getAbout())) return false;
        if (content == null) {
            if (other.getContent() != null) return false;
        } else if (!content.equals(other.getContent())) return false;
        if (metadataType == null) {
            if (other.getMetadataType() != null) return false;
        } else if (!metadataType.equals(other.getMetadataType())) return false;
        if (type == null) {
            if (other.getType() != null) return false;
        } else if (!type.equals(other.getType())) return false;
        return true;
    }

    @Override
    public String toString() {
        return new StringBuilder(getClass().getSimpleName())
                .append("[type:")
                .append(type)
                .append(", metadataType:")
                .append(metadataType)
                .append(", content:")
                .append(content)
                .append(']')
                .toString();
    }
}