Skip to main content
Known Participant
Sep 11, 2023 10:31 AM UTC
Question

How to validate/handle file upload for filename contain double extension?

Hi All,

We have observation from our VA testing team, that while uploading file it should not contain double extension like as shown below:

FileUploadBypass.php%00.xlsx

Currently Appian is allowing to upload the file in to application because of extension .xlsx but VA testing team suggested us to file name should not contain double extension.

Any suggestions on this, how to validate this kind of observation?

Regards,
Sandeep

    10 replies

    stewart.burchell
    Employee
    Sep 11, 2023 10:35 AM UTC

    A file as you describe will have two period characters in its filename so you can simply validate that the filename can only have one period character in it.

    Known Participant
    Sep 11, 2023 10:57 AM UTC

    Thank you Stewart Burchell,

    Could you please suggest some sample validation code, so that i may try to check once.

    Regards,
    Sandeep

    stefanhelzle0001
    Brainy
    Sep 11, 2023 11:10 AM UTC

    len(cleanwith("FileUploadBypass.php%00.xlsx", ".")) > 1

    mathieud0001
    Genius
    Sep 11, 2023 12:03 PM UTC

    I asked ChatGPT to create a Regex. Haven't had time to extensively test it but it's a starting point.

    a!localVariables(
      local!pattern: "^(?=.*\.[^.]+)(?!(?:.*\.[^.]+){2}).*$",
      regexmatch(
        local!pattern,
        "FileUploadBypass.php%00.xlsx"
      )
    )
    

    Known Participant
    Sep 13, 2023 10:36 AM UTC

    Thank you Mathieu Drouin,
    On UI at a!fileUploadField() we have put the given validation.

    Regards,
    Sandeep