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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T14:13:29+00:00 2026-05-28T14:13:29+00:00

What techniques should be used if building UNC paths dynamically, such that to constrain

  • 0

What techniques should be used if building UNC paths dynamically, such that to constrain them to a particular root path.

string root = @"\\Blah\Share\YouStayHere\";

//pretend second string is from a query string a user could manipulate
string path = @"\\Blah\Share\YouStayHere\" + @"..\..\TresspassingQueryString";

if( ! SomeValidation(root, path) ) { throw new Exception("you dirty bastard"...

Granted this should probably be managed with permissions, but maybe the other directory is accessible in the context of another asp page within the same application so permissions wouldn’t be an option.

I know the Request.MapPath can be used to keep access within the application’s directory, but this is a share outside the virtual path of the .NET application.

I was hoping to use Path.Combine to resolve the path and then check to make sure that pathCombined begins with root, but Path.Combine will keep the ….\

Additionally, I imagine there might be other types of injections that someone could do in this situation, so I was hoping for something more generic than just doing a regex for “..\” tokens.

  • 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-28T14:13:30+00:00Added an answer on May 28, 2026 at 2:13 pm

    Use System.IO.Path.GetFullPath to get the combined path with all the \..\ removed.

    Then check that the path still starts with the expected prefix.

    You should put this in an exception handler (if an exception would cause a problem); GetFullPath will access the filesystem (for paths that exist) and if your nefarious client crafts a path that points at an inaccessible folder you’ll get an exception.

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

Sidebar

Related Questions

I'm evaluating a bunch of email validation techniques and someone of them output that
It should be hands-on, complete, targeted to programmers and detailed on layout techniques!
Are there any libraries or techniques that simplify computing equations ? Take the following
I have used OO programming languages and techniques years ago (primarily on C++) but
The ISO definition of generalized markup states: Markup should be rigorous so that the
I've designed a website using some Jquery techniques. My problem is that in some
I have a Flex application that seems larger than it should be. There is
Hi i recently found that JSON is been used in many areas. In COMET
I created a simple a jQuery function that is to be used for developer
I'm currently building a site that gives a lot of sorting options to the

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.