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 3854588
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T17:38:45+00:00 2026-05-19T17:38:45+00:00

Is there a way to validate a file is what it claims to be

  • 0

Is there a way to validate a file is what it claims to be according to it’s file extension?

I have a large number of files that my application copies to a remote server. Before doing each file copy I would like to validate that the file is in fact what the file extension claims it to be.

Right now the user selects the files and/or directories of files using NSOpenPanel. Once I have an array of files I can validate each one physically exists before the copy commences. I have the validation that the source directory is writable working fine and a copy using FSCopyObjectAsync with all the file cancellation in place is also working fine.

The last piece is this validation check. My users are limited in what they can upload, but the filter is done using the file extension. A malicious user could, for example, take a word document file (.doc by file extension) and change it to a .png in order for it to pass the initial open dialog box validation.

This is a rather simplistic example. The files are utilized by the server and I just want to make sure that files that won’t work don’t get uploaded.

I looked at NSFileManager attributeOfItems:atPath:, but it doesn’t seem to offer any information for the real file type. The file type only returns that of a directory, symbolic link etc.

I would rather not attempt to open and load every file to validate, just read the file header and check it conforms to whatever file type spec it needs to.

This is not an iOS app.

Any and all help or pointers in the right direction much appreciated.

  • 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. Editorial Team
    Editorial Team
    2026-05-19T17:38:46+00:00Added an answer on May 19, 2026 at 5:38 pm

    Basically, no. The file system only knows a few very limited things about a file. There can be further metadata associated, but in many cases there won’t be — and in any case, metadata can lie. If you want to be certain that a file really contains what it claims, you need to open it and look.

    Depending on the file type and level of trust, you may not have to look at the whole thing. For example, the file may have a magic number in its first bytes, or there may be other header info that’s enough to convince you. But their presence does not guarantee that the file will “work”.

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

Sidebar

Related Questions

My application has many properties/text configuration files. Is there a common way to validate
Is there a way to validate an XML file against a DTD with Qt's
Is there any way to validate spring context xml files in eclipse? Features like:
Is there way to copy a file into Plone with WebDAV and have Plone
In a jsp file, is there a way to find a component on that
Is there an easy way in C# to validate an html file (.htm) ?
I'm trying to find a way to validate a large XML file against an
Is there a way in your routes file to check and validate URL parameters.
I currently have a requirement where I need to validate that all the files
Is there any way to validate the contents of a CEdit box without subclassing?

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.