Restrict .bat and .exe upload as an attachment

  • 0
  • 1
  • Question
  • Updated 10 months ago
  • Answered
While uploading attachments to the tool in the attachment field i want to restrict the upload of .exe and .bat files in the tool. Is there any way to do that?
Photo of Gaurav

Gaurav

  • 50 Points

Posted 11 months ago

  • 0
  • 1
Photo of Gaurav Sharma

Gaurav Sharma

  • 5,756 Points 5k badge 2x thumb
Hi Gaurav,

There is no native feature for solving this. But, someone from MCF technologies had posted an alternate solution for this.

Please have a look here.

Do let me know if this solution works for you.

Thanks,

Gaurav Sharma
Photo of Nick Davis

Nick Davis

  • 352 Points 250 badge 2x thumb
I wrote this to be used with IOL and it seems to do the trick. This just checks for .bat and .exe extensions, you can add more by including them in the "f_no" expression, separated by pipes. Also, that being said, this just checks the name of the file. So feasibly, someone could take an exe, rename it "virus.txt" and pass the filter. This is sort of hard to lock down without server-side processing at your disposal, but this is a pretty good first line of defense. 


$('input[type=file],select', 'body').attr("onchange", "validate(this)");
//this adds the validate function to every file attachment field in the record

function validate(file) {
    let f_no = /(\.bat|\.exe)$/i;
    let input = $(file);
    let filename = input.val().split('\\').pop();
    let ext = filename.substr( (filename.lastIndexOf('.') +1) );
    if(f_no.test(filename)) {
          alert("To protect against potentially harmful software, we don't allow attachments with certain file extensions, including ."+ ext+ ". Please select either an image, email, document or PDF and try again.");
          input.val("");
    }
}
Photo of Nick Davis

Nick Davis

  • 352 Points 250 badge 2x thumb
Oops, one quick update. 
Change  $('input[type=file],select', 'body')

To $('input[type=file]', 'body')

I had mistakenly grabbed all "select" types, which meant that all drop downs now had a new onchange function. This pushed the native QB functions to onblur, which meant form rules and formulas only ran after the cell was exited. 

Oh well, you live and you learn. 
Photo of Ⲇanom the ultimate (Dan Diebolt)

Ⲇanom the ultimate (Dan Diebolt), Champion

  • 26,322 Points 20k badge 2x thumb
I was wondering about that but I didn't want to take away from the glory of you using IOL!