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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T18:47:27+00:00 2026-05-12T18:47:27+00:00

I want to check that a file system path is valid and safe to

  • 0

I want to check that a file system path is valid and safe to use relative to another path. So I want to know if there are any other special characters like /../ and /./ which might cause a path to actually point somewhere else.

If that is all I have to worry about then a quick replace of those chars followed by something like this to check for any other bad filesystem chars should work right?

[^a-z0-9\.\-_]

(On windows stuff like C:\ would also have to be allowed)

The use case is that I have a folder which site administrators can create directories in and I want to FORCE them to only create directories in that folder. In other words, no being sneaky with ...path/uploads/../../../var/otherfolder/ if you know what I mean 😉

  • 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-12T18:47:27+00:00Added an answer on May 12, 2026 at 6:47 pm

    For resolving paths, ., and .., (and in most cases, // for Unix and \\ for Windows) are the main things you really need to worry about in terms of resolving paths. From RFC 3986, this is the algorithm for resolving relative paths in URIs. For the most part, it also applies to file system paths.

    An algorithm, remove_dot_segments:

    1. The input buffer is initialized with the now-appended path
      components and the output buffer is initialized to the empty
      string.
    2. While the input buffer is not empty, loop as follows:
      1. If the input buffer begins with a prefix of "../" or "./",
        then remove that prefix from the input buffer; otherwise,
      2. If the input buffer begins with a prefix of "/./" or "/.",
        where "." is a complete path segment, then replace that
        prefix with "/" in the input buffer; otherwise,
      3. If the input buffer begins with a prefix of "/../" or "/..",
        where ".." is a complete path segment, then replace that
        prefix with "/" in the input buffer and remove the last
        segment and its preceding "/" (if any) from the output
        buffer; otherwise,
      4. If the input buffer consists only of "." or "..", then remove
        that from the input buffer; otherwise,
      5. Move the first path segment in the input buffer to the end of
        the output buffer, including the initial "/" character (if
        any) and any subsequent characters up to, but not including,
        the next "/" character or the end of the input buffer.
    3. Finally, the output buffer is returned as the result of
      remove_dot_segments.

    Example run:

    STEP   OUTPUT BUFFER         INPUT BUFFER
    
     1 :                         /a/b/c/./../../g
     2E:   /a                    /b/c/./../../g
     2E:   /a/b                  /c/./../../g
     2E:   /a/b/c                /./../../g
     2B:   /a/b/c                /../../g
     2C:   /a/b                  /../g
     2C:   /a                    /g
     2E:   /a/g
    
    STEP   OUTPUT BUFFER         INPUT BUFFER
    
     1 :                         mid/content=5/../6
     2E:   mid                   /content=5/../6
     2E:   mid/content=5         /../6
     2C:   mid                   /6
     2E:   mid/6
    

    Don’t forget that it’s possible to do things like specify more ".." segments than there are parent directories. So if you’re trying to resolve a path, you could end up trying to resolve beyond /, or in the case of Windows, C:\.

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

Sidebar

Related Questions

I want to compare two ms-access .mdb files to check that the data they
I have used checkbox column in gridview. I want to check status of that
I want to check when the user double click on applictaion icon that no
I have a process x that I want to check for leaks with valgrind
I want something that can check if a string is SELECT , INSERT ,
I want to enforce CHECK constraint on a date range such that all dates
I want to check for duplicated words right next to each other, but even
I get a file path to a user file and I want to make
I want to use a temp directory that will be unique to this build.
I am designing a file-server application where I want to check if a cached

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.