Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug] PKCS12 file type validation not working #923

Open
2 tasks done
necik11 opened this issue Jul 17, 2023 · 5 comments
Open
2 tasks done

[Bug] PKCS12 file type validation not working #923

necik11 opened this issue Jul 17, 2023 · 5 comments
Labels

Comments

@necik11
Copy link

necik11 commented Jul 17, 2023

Is there an existing issue for this?

  • I have searched the existing issues

Have you updated FilePond and its plugins?

  • I have updated FilePond and its plugins

Describe the bug

Hi,

first of all I want to show that I found a similar topic/problem - ngx-filepond, I use react not angular and I have the same problem - but i didn't find any solution :)

I would try to elaborate a bit:

I'm trying to make my filepond accepts only pkcs12 (.pfx extension) files using filepond-plugin-file-validate-type. The expected behaviour is that when the dialog to select file opens, only .pfx files would be listed. However, no files are displayed.

I tried multiple ways:
1.

 <FilePond
            files={files}
            allowReorder={true}
            allowMultiple={false}
            allowFileTypeValidation={true}
            acceptedFileTypes={["application/x-pkcs12", "application/pkcs12"]}
          />

and on Q: "Can you confirm the file type the browser detects actually is 'application/x-pkcs12' with this util:" - yes i did. This is exactly the place where i found that i have to use x-pkcs12.
image

I try even fileValidateTypeDetectType but without attribute acceptedFilesTypes its again not working - not call :

 <FilePond
            files={files}
            allowReorder={true}
            allowMultiple={false}
            allowFileTypeValidation={true}
            fileValidateTypeDetectType={(source, type) =>
              new Promise((resolve, reject) => {
                // Do custom type detection here and return with promise
                console.log("source", source);
                console.log("type", type);
                resolve(type);
              })}
          />

and again after add:
acceptedFileTypes={["application/x-pkcs12"]}
stop working and i cant choose any file/certificate.

I even try:

       <FilePond
            files={files}
            allowReorder={true}
            allowMultiple={false}
            allowFileTypeValidation={true}
            acceptedFileTypes={["application/x-pkcs12", "application/x-x509-ca-cert"]}
          />

and this is funny cause its work, but just show certificate/files type .cer ...

Last try was add acceptedFileTypes empty with fileValidateTypeDetectType - i thought it will follow Promise resolve/reject:

    <FilePond
         files={files}
         allowReorder={true}
         allowMultiple={false}
         allowFileTypeValidation={true}
         acceptedFileTypes={[""]}
         fileValidateTypeDetectType={(source, type) =>
           new Promise((resolve, reject) => {
             // Do custom type detection here and return with promise
             console.log("source", source);
             console.log("type", type);
             resolve(type);
           })}
       />

But when i try upload cert its show error: this type is not supported, even there is explicit all resolve(type) ...

so i guess there is more then 3 years a bug which is not solved ? :)

Reproduction

Just install latest version of react-filepond filepond and filepond-plugin-file-validate-type .

Environment

- Device:
- OS: Windows 10
- Browser: Microsoft Edge
@necik11 necik11 added the bug label Jul 17, 2023
@necik11 necik11 changed the title PKCS12 file type validation not working[Bug] [Bug]PKCS12 file type validation not working Jul 17, 2023
@necik11 necik11 changed the title [Bug]PKCS12 file type validation not working [Bug] PKCS12 file type validation not working Jul 17, 2023
@rikschennink
Copy link
Collaborator

You can detect the file type with https://codepen.io/rikschennink/pen/NzRvbj then you add it to the accepted file types list.

In the fileValidateTypeDetectType function you return one of the types in the acceptedFileTypes list.

@necik11
Copy link
Author

necik11 commented Jul 17, 2023

I don't want to be rude, but this is exactly what I wrote in point 1:
and on Q: "Can you confirm the file type the browser detects actually is 'application/x-pkcs12' with this util:" - yes i did. This is exactly the place where i found that i have to use x-pkcs12.:
image

and like i share picture problem is not in part 1, but in part 2:
image

its show just folders ... any files could be selected :) 👍

And yes for any other type of extension seems it works... i was trying .cer - and there is validation working.

@rikschennink
Copy link
Collaborator

rikschennink commented Jul 17, 2023 via email

@necik11
Copy link
Author

necik11 commented Jul 17, 2023

Nope mime is good cause when i set empty acceptedFileTypes with fileValidateTypeDetectType console log:
Case 4 - i can see type is good:
image

But in case i set empty accepted file types i cant upload any file...:
image

so there is no way how to make workaround... just validate on another event what is not much pretty...

@necik11
Copy link
Author

necik11 commented Jul 25, 2023

Here is the same problem with dropzone:

#react-dropzone/react-dropzone#1169

I found a good workaround...

acceptedFileTypes={["application/x-pkcs12", ".pfx"]}

But i still dont understand how should this validation work... cause if I take any guide, it everywhere wrote:

const [files, setFiles] = useState([]);
.
.
.
      <FilePond
                files={files}
                onupdatefiles={setFiles}

But if you write files, the file is uploaded even if there is bad validation.
image

okay i add this method which work, but its really correct ? :

 function onupdatefiles(incomeFiles: FilePondFile[]): void {
        const someError = incomeFiles.some(i => i.status !== 2);
        if (!someError) {
            setFiles(incomeFiles);
        }
    }

From this filepond thing is already giving me a headache, thanks for the answers and advice
Anyway, this code works! 👍

Edit:
When i look on docs:
There is Status & FileStatus:
image

In some reason FilePondFile have only status but there is FileStatus 🤕 :
image

And when validation is Okay it show FaleStatus === 2 => Idle.
In else case 8 === LOAD_ERROR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants