Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
How safe is this: three lines of code.
Old 05-26-2008, 08:37 PM How safe is this: three lines of code.
andrei155's Avatar
CEO of BLD Hosting

Posts: 1,514
Name: Andrei
Location: Canada
Trades: 6
Well I really don't need an php intensive ANYTHING on my website, so don't criticize me for my rather simple script .

I have this running in my "index.php" file:
Code:
<?php

include('overall_header.html');
include('index.html');
include('overall_footer.html');

?>
I use it to separate my documents appropriately, in case a change is necessary.

For example: Lets say I made a spelling error in the header, and i have 1000 pages in HTML. I would have to go to each of those files and fix the error. However with this, i would just have to modify overall_header.html.

Each file i want will create will have the overall_footer.html and overall_header.html, and only a different body file.

I hope this is making sense.

The Question
I know that there is no risk of running pure html files. No places to be hacked or have things injected, and you are generally safe. I also know that php can be a little tougher to secure.

I was wondering if those include commands could be exploited in anyway?
__________________
No Overselling Guarantee
Now Includes a Free Domain
BLD Hosting -
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE
andrei155 is offline
Reply With Quote
View Public Profile Visit andrei155's homepage!
 
 
Register now for full access!
Old 05-26-2008, 10:05 PM Re: How safe is this: three lines of code.
mgraphic's Avatar
Truth Seeker

Latest Blog Post:
JAMISONTUNES
Posts: 2,918
Name: Keith Marshall
Location: Connecticut
Trades: 0
Since you are using hard coded references in the includes, there is no way of this being exploted, except if someone were to get into your FTP (then you would have bigger problems).
__________________

<mgraphic /> - I don't have a solution but I admire the problem.
mgraphic is offline
Reply With Quote
View Public Profile
 
Old 05-26-2008, 10:08 PM Re: How safe is this: three lines of code.
Defies a Status

Posts: 1,606
Trades: 0
As long as you are publishing static read only files there is very little risk IMO.

The hackers exploit DBs, forms and write files.

For a little added "feel good" security and to keep the include files from being indexed you could name them index.html.inc (or most anything you like on Linux server). The included files are parsed as a contribution to the final html output so their names do not matter to the server.
__________________
Colbyt

Please login or register to view this content. Registration is FREE
colbyt is offline
Reply With Quote
View Public Profile
 
Old 05-27-2008, 07:40 AM Re: How safe is this: three lines of code.
andrei155's Avatar
CEO of BLD Hosting

Posts: 1,514
Name: Andrei
Location: Canada
Trades: 6
Okay thats great. Thanks guys
__________________
No Overselling Guarantee
Now Includes a Free Domain
BLD Hosting -
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE
andrei155 is offline
Reply With Quote
View Public Profile Visit andrei155's homepage!
 
Old 05-27-2008, 06:49 PM Re: How safe is this: three lines of code.
JeremyMiller's Avatar
WT Moderator

Posts: 1,712
Name: Jeremy Miller
Location: Las Vegas, NV
Trades: 0
One thing to check is that .html files don't run PHP on your server. Servers can be configured to run PHP and then you'd need to make sure that there's nothing insecure in those included files. The risks for including files which aren't executable is when you do something like this:

PHP Code:
<?php
include ($_GET['file_name']);
?>
Hackers would run rampant with that. If I need to allow a dynamic file choice, I do something like this

PHP Code:
<?php
$sanitized_file 
preg_replace('/[^a-z0-9\-_]/i','',substr($_GET['file_name'],0,-5));
include (
$sanitized_file.'.html');
?>
NOTE: The substr command strips off the last 5 characters which should be the extension if using .html as the extension
or, if I can be a bit more restrictive:

PHP Code:
<?php
$ok_files 
= array(''=>'default_file_name.html',
                  
'file_choice_1'=>'file_1.html'
                  
'file_choice_2'=>'file_2.html',
                  
'file_choice_3'=>'file_3.html'
                 
);
$sanitized_file_name $ok_files[$ok_files[$_GET['file_name']]];
include (
$sanitized_file_name);
?>
By using $ok_files twice in the example above and setting '' to have a value in that array, it auto-filters out bad entries.
__________________
Jeremy Miller

Please login or register to view this content. Registration is FREE

Last edited by JeremyMiller; 05-27-2008 at 06:52 PM.. Reason: Second PHP block code correction
JeremyMiller is offline
Reply With Quote
View Public Profile Visit JeremyMiller's homepage!
 
Old 05-27-2008, 10:08 PM Re: How safe is this: three lines of code.
andrei155's Avatar
CEO of BLD Hosting

Posts: 1,514
Name: Andrei
Location: Canada
Trades: 6
I am not using php in html files. I am using a php file to call 3 html bodies.
__________________
No Overselling Guarantee
Now Includes a Free Domain
BLD Hosting -
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE
andrei155 is offline
Reply With Quote
View Public Profile Visit andrei155's homepage!
 
Old 05-27-2008, 10:10 PM Re: How safe is this: three lines of code.
JeremyMiller's Avatar
WT Moderator

Posts: 1,712
Name: Jeremy Miller
Location: Las Vegas, NV
Trades: 0
I understand. That doesn't mean that your HTML files do not execute PHP code. A server may do that for you without ever asking your permission.
__________________
Jeremy Miller

Please login or register to view this content. Registration is FREE
JeremyMiller is offline
Reply With Quote
View Public Profile Visit JeremyMiller's homepage!
 
Old 05-27-2008, 10:12 PM Re: How safe is this: three lines of code.
andrei155's Avatar
CEO of BLD Hosting

Posts: 1,514
Name: Andrei
Location: Canada
Trades: 6
So, by calling them with php, the html files can now act in the same way as a php file. Or am I not getting this?
__________________
No Overselling Guarantee
Now Includes a Free Domain
BLD Hosting -
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE
andrei155 is offline
Reply With Quote
View Public Profile Visit andrei155's homepage!
 
Old 05-27-2008, 11:49 PM Re: How safe is this: three lines of code.
JeremyMiller's Avatar
WT Moderator

Posts: 1,712
Name: Jeremy Miller
Location: Las Vegas, NV
Trades: 0
You're getting it. Servers can be configured to make any extension go through the PHP engine. It's probable that it's not setup this way on your server, but your question was about making things secure, so I figured that I'd point this out.
__________________
Jeremy Miller

Please login or register to view this content. Registration is FREE
JeremyMiller is offline
Reply With Quote
View Public Profile Visit JeremyMiller's homepage!
 
Old 05-28-2008, 08:06 AM Re: How safe is this: three lines of code.
Defies a Status

Posts: 1,606
Trades: 0
JermyM is correct and servers are not normally set that way unless you modify the .htaccess file.

The simple way to test this is just put some php code in an html file, place it on your server and view the file in a browser.

This will do the job for you:
Quote:
<?PHP
print "hello world html is parsed on your server";
?>
print "if you only see this with the word print, the quotes and semicolon, html is not parsed on your server.";
EDIT: Name that file anything.html
__________________
Colbyt

Please login or register to view this content. Registration is FREE

Last edited by colbyt; 05-28-2008 at 08:10 AM.. Reason: marked
colbyt is offline
Reply With Quote
View Public Profile
 
Old 05-28-2008, 04:30 PM Re: How safe is this: three lines of code.
wayfarer07's Avatar
Poo on You

Latest Blog Post:
Introducing WowWindow
Posts: 3,987
Name: Abel Mohler
Location: Asheville, North Carolina USA
Trades: 0
Personally, I almost always include other .php files into the main body of my pages, because it is very helpful to include dynamic files, whether they are functions or simply behave differently depending on page variables.
__________________
I build web things. I work for the startup
Please login or register to view this content. Registration is FREE
.
wayfarer07 is online now
Reply With Quote
View Public Profile Visit wayfarer07's homepage!
 
Old 05-28-2008, 04:42 PM Re: How safe is this: three lines of code.
JeremyMiller's Avatar
WT Moderator

Posts: 1,712
Name: Jeremy Miller
Location: Las Vegas, NV
Trades: 0
@wayfarer07: I agree too. I don't use html files at all in my coding. The OP, however, seemed very new, though, so I thought it prudent to give him the minimal amount to get on his way.

@OP: You may want to check http://phpsec.org/ and other PHP security resources out there.
__________________
Jeremy Miller

Please login or register to view this content. Registration is FREE
JeremyMiller is offline
Reply With Quote
View Public Profile Visit JeremyMiller's homepage!
 
Old 05-29-2008, 02:36 AM Re: How safe is this: three lines of code.
vn5ltr's Avatar
Skilled Talker

Posts: 93
Location: Melbourne, Australia
Trades: 0
In terms of security, along with some of the other good points mentioned, I would be included any file via an absolute path by use of $_SERVER['DOCUMENT_ROOT']. That way, you know that you will always be starting from the root path of you web directory.
vn5ltr is offline
Reply With Quote
View Public Profile
 
Old 05-29-2008, 02:42 AM Re: How safe is this: three lines of code.
JeremyMiller's Avatar
WT Moderator

Posts: 1,712
Name: Jeremy Miller
Location: Las Vegas, NV
Trades: 0
I don't believe that variable is always defined.
PHP Code:
dirname(__file__
should give you the path to the current file.
__________________
Jeremy Miller

Please login or register to view this content. Registration is FREE
JeremyMiller is offline
Reply With Quote
View Public Profile Visit JeremyMiller's homepage!
 
Old 05-29-2008, 02:43 AM Re: How safe is this: three lines of code.
vn5ltr's Avatar
Skilled Talker

Posts: 93
Location: Melbourne, Australia
Trades: 0
It's always defined for me. Why wouldn't it be?
vn5ltr is offline
Reply With Quote
View Public Profile
 
Old 05-29-2008, 03:37 AM Re: How safe is this: three lines of code.
JeremyMiller's Avatar
WT Moderator

Posts: 1,712
Name: Jeremy Miller
Location: Las Vegas, NV
Trades: 0
Server configuration variations. I believe if you search the PHP site for that variable, you'll see some who have had problems b/c the variable wasn't defined. dirname, and __file__, however, are always defined.
__________________
Jeremy Miller

Please login or register to view this content. Registration is FREE
JeremyMiller is offline
Reply With Quote
View Public Profile Visit JeremyMiller's homepage!
 
Old 05-29-2008, 09:25 AM Re: How safe is this: three lines of code.
shivaji's Avatar
Ultra Talker

Posts: 321
Trades: 0
The best solution for me is define(). I can define any folder in or out of root folder.
Code:
define("PATH", "path/to/folder/");
$include = PATH . "somefile.php";
__________________

Please login or register to view this content. Registration is FREE
- uncommon free scripts

Please login or register to view this content. Registration is FREE
- Städte, Sport, Party, Gourment, Apartments, Hotels
shivaji is offline
Reply With Quote
View Public Profile Visit shivaji's homepage!
 
Old 06-01-2008, 07:46 PM Re: How safe is this: three lines of code.
vn5ltr's Avatar
Skilled Talker

Posts: 93
Location: Melbourne, Australia
Trades: 0
Cool, will take that advice on board.
Cheers.
vn5ltr is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to How safe is this: three lines of code.
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.44620 seconds with 12 queries