close
close

Page 2: Information provided by Java-Bibliotheken, CWE-22

Page 2: Information provided by Java-Bibliotheken, CWE-22

Java Libraries and -Tools can help you create a robust authentication, normalization and security mechanism using CWE-22-Schwachstellen – including:

Anzeige


Apache Commons IO

Apache Commons IO is a database program that will help with a Path-Traversal-Schwachstellen in conjunction with the Data System.

Mold Class DateinameUtils Normalization Methods and Validation of Data.

  import org.apache.commons.io.FilenameUtils;

  String basePath = "/var/www/uploads/";
  String fileName = FilenameUtils.normalize(request.getParameter("file"));

  if (!FilenameUtils.directoryContains(basePath, basePath + fileName)) {
      throw new SecurityException("Attempted path traversal attack detected");
  }

OWASP Java Encoder

The OWASP-Java-Encoder-Bibliothek encoder did not return Eingaben and did not allow Schutz for injections, it was solved very easily and enthalten.

Coder: Bietet Methoden zum sicheren Kodieren von Benutzereingaben für verschiedene Contexte, einschließlich Dateinamen.

  import org.owasp.encoder.Encode;

  String safeFileName = Encode.forJava(request.getParameter("file"));

Apache Shiro

Apache Shiro is a simple Sicherheits framework with a robust Zugriff control mechanism combined with Dateizugriffsrichtlinien.

Data Protection: Shiro uses the simplest Zugriffskontrollrichtlinien described by Dateizugriff.

  // Define file access permissions in Shiro configuration
  (urls)
  /var/www/uploads/** = authc, perms("file:read")

Spring Security

Integrated Sicherheitsframework Spring Security is equipped with Authentication and Automatic Upgrade Mechanisms, optimally integrated in Spring-Anwendung.

Zugangskontrolle: Spring Security can be configured correctly and strengthen Zugriffskontrollen for data sources.

  @PreAuthorize("hasPermission(#filePath, 'read')")
  public void readFile(Path filePath) {
      // read file logic
  }

Apache Tika

Apache Tika is an Early and Extra Library of Metadata and One of the Wide Range of Data Items. Use the updated data program with dateipfaden.

Tika IOUtils: Hilfs Method for Data Processing.

  import org.apache.tika.io.IOUtils;

  String safeFileName = IOUtils.toString(
                                             request.getParameter("file"), 
                                             StandardCharsets.UTF_8);

OWASP Enterprise Security API (ESAPI)

OWASP-ESAPI-Bibliothek can create a good data program for a Sicherheitskontrollen and Dateiverwaltung and help with Path-Traversal-Angriffe.

Validator: Use the ESAPI Validator to validate data.

  import org.owasp.esapi.ESAPI;
  import org.owasp.esapi.Validator;

  Validator validator = ESAPI.validator();
  String safeFileName = validator.getValidInput("file name", 
                                                                                  request.getParameter("file"), 
                                                                                "Filename", 255, false);

Java NIO (New I/O)

Java NIO provides modern APIs for Data Processing, Processing and Validation.

File and Data: Verwenden Sie java.nio.file.Path And java.nio.file.Files für sichere Dateivorgänge.

  import java.nio.file.Path;
  import java.nio.file.Paths;
  import java.nio.file.Files;

  Path basePath = Paths.get("/var/www/uploads/");
  Path filePath = basePath.resolve(request.getParameter("file")).normalize();

  if (!filePath.startsWith(basePath)) {
      throw new SecurityException("Attempted path traversal attack detected");
  }

  if (Files.exists(filePath)) {
      // read file logic
  }

Hibernate Validator

Hibernate Validator, Reference of the Bean Validation API, in some other cases, Validierungseinschränkungen for Benutzereingaben.

Descriptive Definitions: Define authenticating identifiers for the data.

 import javax.validation.constraints.Pattern;

  public class FileRequest {
      @Pattern(regexp = "(a-zA-Z0-9._-)+")
      private String fileName;

      // getters and setters
  }

Java Library and Tools CWE-22-Schwachstellen (Road Crossing) has robust mechanisms for Vermeidung. Mithilfe, Bibliotheken cann man sicherstellen, some Benutzereingaben ordnungsgemäß validiert, Pfade normalisiert und Zugriffskontrollen und und zugriffskontrollen. Risky data transfers are very efficient in terms of data transfers and data transfers provided by Java-Anwendung.

Fundamentals of CWE-22 – Provides more Common Vulnerabilities and Exposures (CVEs) along with a Pfadnames (Path Pass) – Java-Anwendung in a Base Release Release (Path Pass). Perform Real Path Traversal and Traversal Redirects on Core Java Systems and Libraries.

CVE-2020-9484

Beschreibung: Apache Tomcat HTTP/2 Request Smuggling and Path Traversal.
Betroffene Versions: Apache Tomcat 9.0.0.M1 to 9.0.35, 8.5.0 to 8.5.55 and 7.0.0 to 7.0.104.
Einzelheiten: Diese Sicherheitslücke ermöglichte es an Angreifer, Dateien über a special gestaltete Anfrage und beliebige Speicherorte hochzuladen. The problem, which was not related to Benutzereingaben in Datei-Upload-Pfaden, was that a Schwachstelle gave a better result.
Applications: Patch for best practice using updated Apache Tomcat versions.

CVE-2019-0232

Beschreibung: Apache Tomcat Remote-Codeausführung über CGI-Servlet.
Betroffene Versions: Apache Tomcat 9.0.0.M1 to 9.0.17, 8.5.0 to 8.5.39 and 7.0.0 to 7.0.93.
Additionally: CVE stops with a Path Traversal-Schwachstelle during CGI-Servlet-Configuration Manipulation for a Remote Encoding.
Initialization: Disable the CGI server as needed or upgrade to a version of your choice.

CVE-2018-11784

Source: Apache Tomcat
Betroffene Versions: 9.0.0.M1 to 9.0.11, 8.5.0 to 8.5.33 and 7.0.23 to 7.0.90
Versions: Apache Tomcat Release 9.0.0.M1 through 9.0.11, 8.5.0 through 8.5.33, and 7.0.23 through 7.0.90 Standard Server Application A “/foo/”, Regarding Benutzer’s “/foo”), it performs a custom URL creation to generate a URI for a URI to be rendered.
Applications: Patch for best practice using updated Apache Tomcat versions.

CVEs are considered deutlich with Maßnahmen zum Beheben provided by CWE-22-Schwachstellen in Java-Anwendungen sind. Updated current codes for Libraries, Frameworks and Anwendungscodes are the most important elements, a minimized Auswirkungen parser. Make Path Crossovers more efficient using Best Practices for Validation, Normalization, and Robust Sicherheit configurations.

Happy Coding
Sven


(map)