Class SvgUploadValidator

java.lang.Object
org.exoplatform.upload.SvgUploadValidator
All Implemented Interfaces:
UploadFileValidator

public class SvgUploadValidator extends Object implements UploadFileValidator
Rejects unsafe SVG uploads without modifying the uploaded file.

This validator is intentionally SVG-only. Non-SVG files are not opened or parsed by this class.

  • Field Details

    • INFECTED_SVG_MESSAGE

      public static final String INFECTED_SVG_MESSAGE
      See Also:
    • MAX_ELEMENT_DEPTH_PROPERTY

      public static final String MAX_ELEMENT_DEPTH_PROPERTY
      The deepest element nesting an SVG may have, 0 for no limit (the default, as before JDK 25, whose jaxp.properties sets a limit of 100).
      See Also:
  • Constructor Details

    • SvgUploadValidator

      public SvgUploadValidator()
    • SvgUploadValidator

      public SvgUploadValidator(long maxSvgValidationSize)
  • Method Details

    • supports

      public boolean supports(String fileName, String mimeType)
      Specified by:
      supports in interface UploadFileValidator
      Parameters:
      fileName - uploaded file name
      mimeType - detected or enriched MIME type
      Returns:
      true only when this validator must inspect the uploaded file
    • validate

      public void validate(String fileName, String mimeType, InputStream inputStream) throws org.apache.commons.fileupload2.core.FileUploadException
      Description copied from interface: UploadFileValidator
      Validates the uploaded file in read-only mode.

      The provided InputStream is owned by the caller. Implementations must read from it but must not close it.

      The stream is expected to be positioned at the beginning of the uploaded content. When several validators support the same file, the caller should provide a fresh stream to each validator.

      Specified by:
      validate in interface UploadFileValidator
      Parameters:
      fileName - uploaded file name
      mimeType - detected or enriched MIME type
      inputStream - upload file InputStream
      Throws:
      org.apache.commons.fileupload2.core.FileUploadException - when the upload must be rejected