• The Four Hundred
  • Subscribe
  • Media Kit
  • Contributors
  • About Us
  • Contact
Menu
  • The Four Hundred
  • Subscribe
  • Media Kit
  • Contributors
  • About Us
  • Contact
  • Writing Secure PHP Applications

    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

    Share this:

    • Reddit
    • Facebook
    • LinkedIn
    • Twitter
    • Email

    Tags:

    Sponsored by
    Maxava

    Migrate IBM i with Confidence

    Tired of costly and risky migrations? Maxava Migrate Live minimizes disruption with seamless transitions. Upgrading to Power10 or cloud hosted system, Maxava has you covered!

    Learn More

    Share this:

    • Reddit
    • Facebook
    • LinkedIn
    • Twitter
    • Email

    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

    SugarCRM Supports Smart Phones, Including Windows Mobile Bsafe Updates Security Tools for i OS

    Leave a Reply Cancel reply

Volume 8, Number -- May 14, 2008
THIS ISSUE SPONSORED BY:

ProData Computer Services
WorksRight Software
COMMON

Table of Contents

  • Writing Secure PHP Applications
  • Use PCOMM Scripts to Execute Remote PC Commands, Part 1
  • Admin Alert: Things to Do When Adding Drives to a System
  • SQL Doesn’t Like Logical Files
  • Performance Advice from a Mysterious Friend, Part 4
  • Admin Alert: V6R1 Changes for the i5/OS Administrator, Part 1

Content archive

  • The Four Hundred
  • Four Hundred Stuff
  • Four Hundred Guru

Recent Posts

  • Public Preview For Watson Code Assistant for i Available Soon
  • COMMON Youth Movement Continues at POWERUp 2025
  • IBM Preserves Memory Investments Across Power10 And Power11
  • Eradani Uses AI For New EDI And API Service
  • Picking Apart IBM’s $150 Billion In US Manufacturing And R&D
  • FAX/400 And CICS For i Are Dead. What Will IBM Kill Next?
  • Fresche Overhauls X-Analysis With Web UI, AI Smarts
  • Is It Time To Add The Rust Programming Language To IBM i?
  • Is IBM Going To Raise Prices On Power10 Expert Care?
  • IBM i PTF Guide, Volume 27, Number 20

Subscribe

To get news from IT Jungle sent to your inbox every week, subscribe to our newsletter.

Pages

  • About Us
  • Contact
  • Contributors
  • Four Hundred Monitor
  • IBM i PTF Guide
  • Media Kit
  • Subscribe

Search

Copyright © 2025 IT Jungle