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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T13:44:40+00:00 2026-06-11T13:44:40+00:00

Now I’m wondering if is is safe to require files with only require($path) .

  • 0

Now I’m wondering if is is safe to require files with only require($path).

For just simpliest example:
I have some form field folder and name. So when I do require($somepath.'/'.$folder.'/'.$name.'.php') it can be easily relocated with inputing ‘../../admin/or/else/things/’.

It is simple example, but there are (i expect so) many other ways to relocate $path.

So the question is:
– provide checks of incoming path?
– if yes.. so how do it correctly?

  • 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-06-11T13:44:41+00:00Added an answer on June 11, 2026 at 1:44 pm

    If you want to require another file, based on user input, you should validate the folder and name fields very carefully. You don’t want users to require their own files (maybe a file they just uploaded) or any other nasties.

    Ideally, you should create a list of acceptable values, like so:

    $allowedIncludes = array('a/foo.php', 'b/bar.php'); // etc
    

    Then you can just check whether the combination of name and folder fields they provided is valid:

    if(false !== array_search("$folder/$name", $allowedIncludes) {
      // OK
      // require ...;
    } else {
      // not ok
    }
    

    But again, be very careful when allowing users to do things like this. You do not want to allow people to execute arbitrary code on your machine.

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

Sidebar

Related Questions

Now facebook require to have these options when you want to use bulit-in actions
I have just tried to save a simple *.rtf file with some websites and
Now that we soon have user defined literals (UDL), in GCC 4.7 for example,
Now I have a table with impressions, clicks and ctr. I was wondering if
now form what i have seen in the documentary of twitter bootstrap tabs, the
Now on writing path as sys.path.insert(0,'/home/pooja/Desktop/mysite'), it ran fine asked me for the word
Now I am wondering if you guys could help me on serializing an ArrayList
Now I am creating an address book in Java 1.6. Now how I have
Now I have a long query and I'd like to alternate with such a
I have a jquery bug and I've been looking for hours now, I can't

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.