fhg
Volume 8, Number -- May 14, 2008

Writing Secure PHP Applications

Published: May 14, 2008

Hey, Pat:

My company has been playing around with PHP for a while. We are now designing real applications that we will deploy through our own Web server. What security ramifications do we need to consider in our design?


Thank you for your question.

Four aspects of PHP need to be considered to deal appropriately with security design in PHP applications:

  1. PHP architecture on i5/OS
  2. Web server application security design and configuration
  3. Built-in PHP i5_* and db2_* functions
  4. Your current object level access control methodology for i5/OS resources

The i5/OS PHP architecture consists of two Web server instances--the PHP core engine running in PASE, and i5/OS specific built-in functions i5_* and db2_*. The Web server instance that listens for requests from the network is the native i5/OS Apache Web server. It is configured to redirect all requests to a second Web server--an instance of the AIX-based Apache Web server running in PASE. The PASE Web server instance is configured to only accept requests from the localhost (programs running on the same system) on port 8000. In theory, users cannot talk directly to the PASE Apache Web server remotely. Note, however, that due to the way the proxy and reverse proxy Apache configuration attributes work, a user can access URLs representing directories served only by the PASE Apache Web server. Therefore proper security configuration of both Web servers is necessary!

The PHP install process performs the initial configuration of a bunch of stuff, including both Web servers. You can further tighten the configuration of these to limit their usage to only those PHP applications and the directories in which those application files exist. The goal is to prevent a knowledgeable user from using the Web server instances for PHP to point to any arbitrary directory on your system.

The external Web server instance receives a request and redirects the request to localhost:8000. The AIX-based Web server instance parses the request. PHP code is recognized and handled by the core PHP process running in AIX. This process runs under the i5/OS user profile named "nobody" that is created during the PHP install process.

PHP code can directly access i5/OS and DB2 resources by using the built-in i5_* and db2_* PHP functions. To use these functions, the PHP program must first call the "i5_connect()" or "db2_connect()" function. These functions, among other things, establish the user profile under which all other i5_ (or db2_ ) functions execute for that particular request. If the a userID and password are not provided on the i5_connect() function, the request runs under user profile "nobody."

Normally, you should NEVER hardcode user IDs and passwords in an application. Therefore, you either do not supply a userID and password to the request or you need to get the userID and password to use through the Web page from the user. If you provide no userID and password, calls to subsequent i5_* (or db2_*) functions are performed under user profile "nobody."

When getting data from users, which is handled by PASE-based applications, you have to follow coding practices that avoid buffer overflow flaws. This means you have to add code to perform a validity check on all of the data provided directly or indirectly by an end user (e.g., acceptable pathname and length, valid user ID name and length, valid password length, etc.). This is especially true for any data that is used as input for the i5_* and db2_* functions. Make sure the data is of a reasonable length and that you don’t blindly pass pointers to data without ensuring they are reasonably formatted including null terminators, etc.

The final aspect to consider is the object level access control methodology you use on your system. If you are like most customers, you probably have the default authority on your directories, libraries, and objects set to *CHANGE or higher. Now, when you consider there is no exit point for calls from the PHP engine running in PASE to native i5/OS resources, any user profile including "nobody" and the user ID provided by the user can access anything; exit point programs cannot detect or prevent this. This is another reason why I believe an exclusionary access control model (default authority to sensitive data, libraries, programs is set to *EXCLUDE, relying on adopted authority wherever possible and a limited amount of private authorities when absolutely necessary).

For those IFS directories containing PHP programs, exclude PUBLIC, and grant private *X authority to profiles under which the Web server is running and to the "nobody" user profile. Grant private *R authority to stream files in those directories.

To protect i5/OS libraries and objects, you also need PUBLIC *EXCLUDE and private *USE/*CHANGE as required by the PHP applications and the i5/OS applications that use those libraries and objects. Note that "private" authority includes private authority for user profiles and/or groups directly to the library or object or to an authorization list that protects that particular library or object.

In short, running PHP applications securely requires you to:

  • Configure the PHP related Web server instances to only accept requests for directories specifically containing PHP related files and applications
  • Perform validity-checking, bounds-checking, and sanity-checking in your PHP application on all parameters that are not hardcoded
  • Use an exclusionary access control model where PUBLIC authority to sensitive resources is *EXCLUDE

Pat Botz is vice president of security consulting at Group 8 Security. He has over 25 years of experience in the computer industry, including the UNIX, AS/400, and System i markets. He spent nine years as a member, team leader, and lead architect for IBM's OS/400 and i5/OS security team. Pat has been a speaker at numerous industry events including COMMON and the IBM Tech Conferences and is a co-author of the book, "Experts' Guide to OS400 and i5/OS Security."




                     Post this story to del.icio.us
               Post this story to Digg
    Post this story to Slashdot


Sponsored By
PRODATA COMPUTER SERVICES

Push-Pull-Synchronize Data TODAY!

Finally, a product that provides easy and full SQL access to remote databases
from all System i high-level languages. Remote Database Connect gives you
easy access to remote databases from your System i programs.

Share real time data across platforms NOW!

Use RDB Connect today.....
download a free trial NOW.

Order today and SAVE $$$!
800.228.6318

sales@prodatacomputer.com
www.prodatacomputer.com


Senior Technical Editor: Ted Holt
Technical Editor: Joe Hertvik
Contributing Technical Editors: Edwin Earley, Brian Kelly, Michael Sansoterra
Publisher and Advertising Director: Jenny Thomas
Advertising Sales Representative: Kim Reed
Contact the Editors: To contact anyone on the IT Jungle Team
Go to our contacts page and send us a message.

Sponsored Links

Vibrant Technologies:  The leading source for IBM Power Systems and Upgrades
COMMON:  Join us at the Focus 2008 workshop conference, October 5 - 8, in San Francisco, California
Vision Solutions:  System i Management Tips Blog - Free i5/OS Tips Each Week!


 

IT Jungle Store Top Book Picks

Easy Steps to Internet Programming for AS/400, iSeries, and System i: List Price, $49.95
Getting Started with PHP for i5/OS: List Price, $59.95
The System i RPG & RPG IV Tutorial and Lab Exercises: List Price, $59.95
The System i Pocket RPG & RPG IV Guide: List Price, $69.95
The iSeries Pocket Database Guide: List Price, $59.00
The iSeries Pocket Developers' Guide: List Price, $59.00
The iSeries Pocket SQL Guide: List Price, $59.00
The iSeries Pocket Query Guide: List Price, $49.00
The iSeries Pocket WebFacing Primer: List Price, $39.00
Migrating to WebSphere Express for iSeries: List Price, $49.00
iSeries Express Web Implementer's Guide: List Price, $59.00
Getting Started with WebSphere Development Studio for iSeries: List Price, $79.95
Getting Started With WebSphere Development Studio Client for iSeries: List Price, $89.00
Getting Started with WebSphere Express for iSeries: List Price, $49.00
WebFacing Application Design and Development Guide: List Price, $55.00
Can the AS/400 Survive IBM?: List Price, $49.00
The All-Everything Machine: List Price, $29.95
Chip Wars: List Price, $29.95


 
The Four Hundred
The i Platform Roadmap Is a Work in Progress

IBM Loses Two Key Executives to Retirement--Really

Java Performance Is OS Agnostic on Power6 Gear

As I See It: Soothing the Savage Programmer

IBM Goes Stateless and Cooler with iDataPlex Servers

The Linux Beacon
AMD Revises Opteron Roadmaps, Pushes Out Rev Gs

New and Updated Barcelona Boxes Debut from Sun

Java Performance Is OS Agnostic on Power6 Gear

As I See It: Soothing the Savage Programmer

Virtual Server Sprawl Reeled In with Tideway Foundation 7.1

Four Hundred Stuff
Aldon Responds to Business Pressures on IT Departments

Former Magic CEO Sues as iBOLT Sales Channel Widened

MKS Updates Change Management for i OS, Warns of Big Revenue Jump

INGENICA Updates Universal Print Driver

Original Software Now Supports Mainframe in TestDrive-Assist

Big Iron
The Modern Mainframe: A Model of Space and Energy Efficiency

Top Mainframe Stories From Around the Web

Chats, Webinars, Seminars, Shows, and Other Happenings

System i PTF Guide
May 3, 2008: Volume 10, Number 18

April 26, 2008: Volume 10, Number 17

April 19, 2008: Volume 10, Number 16

April 12, 2008: Volume 10, Number 15

April 5, 2008: Volume 10, Number 14

March 29, 2008: Volume 10, Number 13

The Windows Observer
Microsoft Withdraws Yahoo Bid, Won't Go Hostile

GDCM Seeks to 'Defrag' the Data Center for Higher Efficiency

Hey ASA: Microsoft Delivers New Automated Service Agent

The X Factor: Everybody Wants Citrix Systems?

SugarCRM Supports Smart Phones, Including Windows Mobile

The Unix Guardian
Sun Delivers OpenSolaris Development Distro, Plus Support

AMD Revises Opteron Roadmaps, Pushes Out Rev Gs

IBM Loses Two Key Executives to Retirement--Really

GDCM Seeks to 'Defrag' the Data Center for Higher Efficiency

Power Systems: The Feeds and Speeds

Four Hundred Monitor
Four Hundred Monitor's
Full iSeries Events Calendar

THIS ISSUE SPONSORED BY:

ProData Computer Services
WorksRight Software
COMMON


Printer Friendly Version


TABLE OF CONTENTS
Writing Secure PHP Applications

Use PCOMM Scripts to Execute Remote PC Commands

Admin Alert: Things to Do When Adding Drives to a System

Four Hundred Guru

BACK ISSUES

From the IT Jungle Forums
Java Messages

Restrict *cmd to specific user

Copying recs from a subfile to a file and keeping highlights

Imbedded SQL

CPYFRMSTMF problem

CPYTOIMPF problem





 
Subscription Information:
You can unsubscribe, change your email address, or sign up for any of IT Jungle's free e-newsletters through our Web site at http://www.itjungle.com/sub/subscribe.html.

Copyright © 1996-2008 Guild Companies, Inc. All Rights Reserved.
Guild Companies, Inc., 50 Park Terrace East, Suite 8F, New York, NY 10034

Privacy Statement