Adobe
Products

Top destinations

  • Adobe Creative Cloud
  • Creative Suite
  • Adobe Marketing Cloud
  • Acrobat
  • Photoshop
  • SiteCatalyst
  • Students
  • Elements family

Adobe Creative Cloud

  • What is Adobe Creative Cloud?
  • Design
  • Web
  • Photography
  • Video
  • Students
  • Teams
  • Enterprise
  • Educational institutions

Design and photography

  • Photoshop
  • Illustrator
  • InDesign
  • Adobe Muse
  • Lightroom

Video

  • Adobe Premiere
  • After Effects

Web development and HTML5

  • Edge Tools & Services [opens in a new window]
  • Dreamweaver
  • Gaming [opens in a new window]

Adobe Marketing Cloud

  • What is Adobe Marketing Cloud?
  • Digital analytics
  • Social marketing
  • Web experience management
  • Testing and targeting
  • Media optimization

Analytics

  • SiteCatalyst
  • Adobe Discover
  • Insight

Social

  • Adobe Social

Experience Manager

  • CQ
  • Scene7

Target

  • Test&Target
  • Recommendations
  • Search&Promote

Media Optimizer

  • AdLens
  • AudienceManager
  • AudienceResearch

Document services

  • Acrobat
  • EchoSign [opens in a new window]
  • FormsCentral [opens in a new window]
  • SendNow [opens in a new window]
  • Acrobat.com [opens in a new window]

Publishing

  • Digital Publishing Suite

  • See all products
Business solutions

By business need

  • Digital analytics
  • Digital publishing
  • Document management
  • Media optimization
  • Social marketing
  • Testing and targeting
  • Video editing and serving
  • Web development [opens in a new window]
  • Web experience management
  • See all business needs

By industry

  • Broadcast
  • Education
  • Financial services
  • Government
  • Publishing
  • Retail
  • See all industries
Support & Learning

I need help

  • Products
  • Adobe Creative Cloud
  • Adobe Marketing Cloud
  • Forums [opens in a new window]

I want to learn

  • Training and tutorials
  • Certification [opens in a new window]
  • Adobe Developer Connection
  • Adobe Design Center
  • Adobe TV [opens in a new window]
  • Adobe Marketing Center
  • Adobe Labs [opens in a new window]
Download
  • Product trials
  • Adobe Flash Player
  • Adobe Reader
  • Adobe AIR
  • See all downloads
Company
  • Careers at Adobe
  • Investor Relations
  • Newsroom
  • Privacy
  • Corporate Social Responsibility
  • Customer Showcase
  • Contact us
  • More company info
Buy
  • For personal and professional use
  • For students, educators, and staff
  • For small and medium businesses
  • Volume Licensing
  • Special offers
  • Adobe Marketing Cloud sales [opens in a new window]
Search
 
Info Sign in
Why sign in? Sign in to manage your account and access trial downloads, product extensions, community areas, and more.
Welcome,
My Adobe
My orders
My information
My preferences
My products and services
Sign out
My cart
Privacy My Adobe
Adobe
Products Sections Buy   Search  
Solutions Company
Help Learning
Sign in Sign out Privacy My Adobe
Date Date
Qty:
Subtotal
Promotions
Estimated Shipping
VAT
Calculated at checkout
Total
Checkout
Dreamweaver Help / 

Protecting PHP server behaviors from SQL injection vulnerability

Adobe Community Help


Products Affected

  • Dreamweaver

Contact support

 
By clicking Submit, you accept the Adobe Terms of Use.
 

Issue

Some databases let you send multiple SQL statements in a single query. Because of this, there are potential security risks when you pass parameters in a query string to a dynamically generated database query. Hackers might try to modify URL or form variables in a dynamic query by appending malicious SQL statements to existing parameters. This is often referred to as a SQL injection attack. Some of the server behavior code created by Dreamweaver should be modified to reduce the risk of SQL injection attacks. For more background information on SQL injection, see this Wikipedia article. (Ref. 201713)

Note: The issue described in this TechNote has been fixed in the Dreamweaver 8.0.2 Updater.

This TechNote covers Dreamweaver's PHP server behaviors. There are separate TechNotes for the ColdFusion, ASP VBScript, ASP JavaScript and JSP server behaviors. The ASP.NET server behaviors are not affected.

To the top

Solution

When you let a query string pass a parameter, ensure that only the expected information is passed. Adobe has created a Dreamweaver 8.0.2 Updater that reduces the risk of SQL injection attacks. These fixes will be incorporated into all future releases of Dreamweaver. After updating Dreamweaver 8, you will need to reapply the server behaviors to the pages that use them, and redeploy those pages to your server.

The remainder of this TechNote documents how to manually edit Dreamweaver MX 2004 code to prevent SQL injection attacks with the PHP server model. Server behaviors that are vulnerable to these attacks are listed below, along with fixes:

  • Recordset with a filter
  • Insert, Update, and Delete Record server behaviors and Record Insertion Form Wizard
  • Log In User
  • Check New User
  • Master Detail Page Set
  • Record Update Form Wizard

Recordset with a filter

Unfiltered recordsets do not need to be modified, but filtered recordsets do. In the example below, a Dreamweaver MX 2004 recordset named "rs_byDate" is filtered by a date value passed in from a URL parameter. The highlighted code below is what will need to be changed:

<?php $colname_rs_byDate = "1"; if (isset($_GET['relDate'])) {   $colname_rs_byDate = (get_magic_quotes_gpc()) ? $_GET['relDate'] : addslashes($_GET['relDate']); } mysql_select_db($database_dreamqa2, $dreamqa2); $query_rs_byDate = sprintf("SELECT * FROM albums WHERE relDate = '%s'", $colname_rs_byDate); $rs_byDate = mysql_query($query_rs_byDate, $dreamqa2) or die(mysql_error()); $row_rs_byDate = mysql_fetch_assoc($rs_byDate); $totalRows_rs_byDate = mysql_num_rows($rs_byDate); ?>

To protect the recordset from SQL injection attacks, a custom GetSQLValueString() function should be created near the top of the page. This function will verify the data type of the query parameter. Once the function has been created, then update the recordset code to use the GetSQLValueString() function.

  1. Go to the second line in code view, right after the include file for the connection, and add the GetSQLValueString() function to the beginning of the code as follows:
    <?php if (!function_exists("GetSQLValueString")) { function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")  {   $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;   $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);   switch ($theType) {     case "text":       $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";       break;      case "long":     case "int":       $theValue = ($theValue != "") ? intval($theValue) : "NULL";       break;     case "double":       $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";       break;     case "date":        $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";        break;     case "defined":       $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;       break;   }   return $theValue; } } ?>
  2. Remove the magic quotes code so that backslashes are not incorrectly added to GET and POST data when magic quotes are turned off on the PHP server.

    Original code:

    $colname_rs_byDate = (get_magic_quotes_gpc()) ? $_GET['relDate'] : addslashes($_GET['relDate']);
    Modified code:

    $colname_rs_byDate = $_GET['relDate'];


  3. Update the recordset code to create a SQL string using the GetSQLValueString() function created above. Update the value of the variable $query_rs_byDate:



    Original code:
    $query_rs_byDate = sprintf("SELECT * FROM albums WHERE relDate = '%s'", $colname_rs_byDate);


    Modified secured code:
    $query_rs_byDate = sprintf("SELECT * FROM albums WHERE relDate = %s", GetSQLValueString($colname_rs_byDate, "date"));

Insert, Update, and Delete Record server behaviors and Record Insertion Form Wizard

The Insert, Update and Delete Record server behaviors and Record Insertion Form Wizard already use the GetSQLValueString() function, so they just need to be refined to prevent SQL injections. The only changes needed are in the GetSQLValueString() function.

Here is the original code. The line that will be changed is highlighted in yellow:

if (!function_exists("GetSQLValueString")) { function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")    {$theValue = (!get_magic_quotes_gpc()) ? addslashes($theValue) : $theValue;   switch ($theType) {     case "text":       $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";       break;      case "long":     case "int":       $theValue = ($theValue != "") ? intval($theValue) : "NULL";       break;     case "double":       $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";       break;     case "date":       $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";       break;     case "defined":       $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;       break;   }   return $theValue; } }

Update the definition of the variable $theValue:

Original code:

$theValue = (!get_magic_quotes_gpc()) ? addslashes($theValue) : $theValue;

Modified secured code:

$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue; $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

Log In User server behavior

Here are the steps to fix the Log In User server behavior:

  1. Create a GetSQLValueString() function as described in Recordset with a filter above.
  2. Modify the code that constructs the login SQL query.



    Original code:
    $LoginRS__query=sprintf("SELECT username, password FROM login WHERE username='%s' AND password='%s'",    get_magic_quotes_gpc() ? $loginUsername : addslashes($loginUsername), get_magic_quotes_gpc() ? $password : addslashes($password));


    Modified secured code:
    $LoginRS__query=sprintf("SELECT username, password FROM login WHERE username=%s AND password=%s",    GetSQLValueString($loginUsername, "text"), GetSQLValueString($password, "text"));

Check New User server behavior

The Check New User server behavior requires that an Insert Record server behavior be added to the page first. The GetSQLValuesString() function is included with the Insert Record server behavior. All that needs to be done is to update the GetSQLValuesString() to better handle SQL Injection and update the Check New User server behavior to use this function when a parameter is passed in.

  1. Change the first line in the function to update the GetSQLValuesString() function as described in Update the definition of the variable $theValue.
  2. Modify the code to construct the login SQL query to use the GetSQLValuesString() to pass in parameters. Towards the top of the page, locate the code in the section starting with // *** Redirect if username exists.



    Original code:
    $LoginRS__query = "SELECT username FROM login WHERE username='" . $loginUsername . "'"


    Modified secured code:
    $LoginRS__query = sprintf("SELECT username FROM login WHERE username=%s", GetSQLValueString($loginUsername, "text"));

Master Detail Page Set

For the Master Detail Page Set application object, the changes are mainly in the recordset that Dreamweaver creates for the Detail Page. If you don't have a filtered recordset in the Master Page, then no changes need to be made to the Master Page. If you have a filtered recordset, then see recordset with a filter to update the recordset code.

Dreamweaver creates a filtered recordset in the Detail Page, so that recordset code needs to be updated to use a GetSQLValueString() function to pass in parameters and sprintf() to construct the SQL string.

  1. Create the GetSQLValueString() function as described in Recordset with a filter above.
  2. Update the variable declaration code and construct the SQL query using the GetSQLValuesString() function.



    Original code:
    $recordID = $_GET['recordID']; $query_DetailRS1 = "SELECT * FROM albums WHERE ID = $recordID";


    Modified secured code:
    $colname_DetailRS1 = "-1"; if (isset($_GET['recordID'])) { $colname_DetailRS1 = (get_magic_quotes_gpc()) ? $_GET['recordID'] : addslashes($_GET['recordID']); } $query_DetailRS1 = sprintf("SELECT * FROM albums WHERE ID = %s", GetSQLValueString($colname_DetailRS1, "int"));

Record Update Form Wizard

  1. Update the definition of the variable $theValue as described in Insert, Update, and Delete Record server behaviors and Record Insertion Form Wizard.
  2. Update the code for the Recordset which is required for the Record Update Form as described in step 2 of Recordset with a filter.
To the top

Additional Information

Please refer to the following article for more information about SQL injection: Wikipedia article on SQL injection.

Adobe Security Bulletin: APSB 06-07 Dreamweaver Server Behavior SQL Injection vulnerability.

Keywords: 30037473

This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License  Twitter™ and Facebook posts are not covered under the terms of Creative Commons.

Legal Notices   |   Online Privacy Policy

Products

  • Adobe Creative Cloud
  • Creative Suite
  • Adobe Marketing Cloud
  • Acrobat
  • Photoshop
  • Digital Publishing Suite
  • Elements family
  • SiteCatalyst
  • For education

Download

  • Product trials
  • Adobe Reader
  • Adobe Flash Player
  • Adobe AIR

Support & Learning

  • Product help
  • Forums

Buy

  • For personal and professional use
  • For students, educators, and staff
  • For small and medium businesses
  • Volume Licensing
  • Special offers

Company

  • News room
  • Partner programs
  • Corporate social responsibility
  • Career opportunities
  • Investor Relations
  • Events
  • Legal
  • Security
  • Contact Adobe
Choose your region United States (Change)
Choose your region Close

North America

Europe, Middle East and Africa

Asia Pacific

  • Canada - English
  • Canada - Français
  • Latinoamérica
  • México
  • United States

South America

  • Brasil
  • Africa - English
  • Österreich - Deutsch
  • Belgium - English
  • Belgique - Français
  • België - Nederlands
  • България
  • Hrvatska
  • Česká republika
  • Danmark
  • Eastern Europe - English
  • Eesti
  • Suomi
  • France
  • Deutschland
  • Magyarország
  • Ireland
  • Israel - English
  • ישראל - עברית
  • Italia
  • Latvija
  • Lietuva
  • Luxembourg - Deutsch
  • Luxembourg - English
  • Luxembourg - Français
  • الشرق الأوسط وشمال أفريقيا - اللغة العربية
  • Middle East and North Africa - English
  • Moyen-Orient et Afrique du Nord - Français
  • Nederland
  • Norge
  • Polska
  • Portugal
  • România
  • Россия
  • Srbija
  • Slovensko
  • Slovenija
  • España
  • Sverige
  • Schweiz - Deutsch
  • Suisse - Français
  • Svizzera - Italiano
  • Türkiye
  • Україна
  • United Kingdom
  • Australia
  • 中国
  • 中國香港特別行政區
  • Hong Kong S.A.R. of China
  • India - English
  • 日本
  • 한국
  • New Zealand
  • 台灣

Southeast Asia

  • Includes Indonesia, Malaysia, Philippines, Singapore, Thailand, and Vietnam - English

Copyright © 2013 Adobe Systems Incorporated. All rights reserved.

Terms of Use | Privacy | Cookies

Ad Choices

Reviewed by TRUSTe: site privacy statement