Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 170247
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T12:46:28+00:00 2026-05-11T12:46:28+00:00

my proble is to avoid that users upload some malicious file on my web-server.

  • 0

my proble is to avoid that users upload some malicious file on my web-server. Im working on linux environment (debian).

Actually the uploads are handled via php by this code:

function checkFile($nomeFile, $myExt = false){ if($myExt != false){ $goodExt = '_$myExt'.'_'; }else{ $goodExt = '_.jpg_.bmp_.zip_.pdf_.gif_.doc_.xls_.csv_.docx_.rar_'; } $punto = strrpos($nomeFile, '.'); $ext = '_'.substr($nomeFile, $punto, 8).'_'; if(stristr($goodExt, $ext)){ return 1; }else{ return 0; } } 

here i can specify the extensions allowed to be uploaded, and if the file dont meet them i delete as soon as the upload is completed. But this way let the user free to change the file extension with a simple rename.. and thats bad for me; even if a file.exe (for example) wont never be executed if is renamed in file.jpg (am i right?), i dont want to have potential danger files on my server.

There is a way, in php, python, or whatelse can a unix system run easly, to check the truly type of a file?

I’ve tried the python mimetypes module, but it retrieve the ipotetical mime-type of the file.. based on the extension -.-

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T12:46:29+00:00Added an answer on May 11, 2026 at 12:46 pm

    You’re going to need to validate that the uploaded file is actually the type that the extension indicates it is. You can do that through various methods, probably the easiest is via the file command. I don’t know if it has an API. You can try it out yourself in the shell. For your example of file.exe that was renamed to file.jpg before being uploaded, run file file.jpg and it will print out something telling you it’s an executable. It can be fooled, however.

    I’m guessing you don’t know much about Linux file permissions if you think .exe means it will be executed. On linux, only the execute bit in the file permissions determine that — you can execute any file, regardless of extension, if that bit is turned on. Don’t set it on any uploaded files and you should be safe from executing them. You may still be serving them back up to your site’s visitors, so it could still be a vector for XSS attacks, so watch out for that.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 113k
  • Answers 113k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer This is called the transitive reduction problem. Formally speaking, you… May 11, 2026 at 10:02 pm
  • Editorial Team
    Editorial Team added an answer Check out: Matt Gallagher's property accessors script for XCode Accessorizer… May 11, 2026 at 10:02 pm
  • Editorial Team
    Editorial Team added an answer If you're looking for some way to mark the first… May 11, 2026 at 10:02 pm

Related Questions

I have a website where users can create albums and then add images to
I have read through the solutions to similar problems, but they all seem to
I got a webserver with a running application. There's a webpage with a form:
I am currently working on a web application that uses PHP and MySQL, but

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.