News:

SMF 2.1.4 has been released! Take it for a spin! Read more.

Main Menu

Security practices on creating modifications

Started by Harzem, October 11, 2006, 05:25:18 PM

Previous topic - Next topic

Neorics

so correct me if i'm wrong but this tip is only for mod writers? i mean does SMF have this feature already in it's system?

cause i'm planning to customize the 'edit profile' page to restrict certain fields to be able to be viewed/edited by certain member groups and i'll be using if($context statemets

so is it safe to do that?
[For Hire] I can help you with anything regarding Simple Machines Forum  ~ My Portfolio

karlbenson

any fields you add where users can enter information need

-sanitising (eg casting as integer or removing bad characters)
-validating (eg if it was a youtube id, you would validate to check its a-zA-Z0-9- in a preg_match)
-escaping (if being inserted in the database) addslashes___resursive($data);

Neorics

Quote from: karlbenson on September 22, 2007, 05:27:06 PM
any fields you add where users can enter information need

-sanitising (eg casting as integer or removing bad characters)
-validating (eg if it was a youtube id, you would validate to check its a-zA-Z0-9- in a preg_match)
-escaping (if being inserted in the database) addslashes___resursive($data);

ok... i'm totally lost... can you point me to a direction where i can read how to do those you mentioned?
[For Hire] I can help you with anything regarding Simple Machines Forum  ~ My Portfolio

karlbenson

Well there isn't any specific smf code functions for doing the above.

You will need to use functions like preg_match, eregi, preg_replace with regex strings.

Santiizing eg if you've got an integer you can make sure its an integer
$string = (int) $string;

If it wasn't a number, it will be 0.

You'll find lots of examples of validating/santizing in mods.
Eg my youtube mod checks if the data being parsed is a valid youtube id (a-zA-Z0-9-)

if (preg_match(\'#^([0-9A-Za-z-_]{11})#i\', trim($data[0]), $matches)) {

More info
http://uk3.php.net/preg_match
http://uk3.php.net/preg_replace

Neorics

thanks, omg i didnt realize that SMF have a google ad at the bottom... just saw it after opening it in IE...
[For Hire] I can help you with anything regarding Simple Machines Forum  ~ My Portfolio


BuЯЯЯЯaK


Informatics

wow... cool, thanx for posting.
Modders have to read this


You can catch me @ Forum Informatika a.k.a Indonesian Informatics Online Community @ http://if.web.id




Mods:
1. LinkTree v.1.1.0 [Topic  || Download]
2. Header Rotator v.1.1.0 for 1.1.x | v.2.1 for 2.0 [Topic || Download]

Kader

Hi all

Can somebody shed some light on how:
db_query()

can replace:

$link = mysql_connect('host', 'root', 'password')
    or die('Could not connect: ' . mysql_error());

This is to avoid having the password hanging around in a file.

Thanx all

metallica48423

have you looked at the function DB entry for db_query? 

db_query will use the SMF connection to make the query in the first parameter of it.  The second and third parameter should be __FILE__ and __LINE__

ie:


$id = db_query("
    SELECT ID_MEMBER
    FROM smf_members
    WHERE realName = 'metallica48423'", __FILE__, __LINE__);


will store the result of the query in $id

Justin O'Leary
Ex-Project Manager
Ex-Lead Support Specialist

QuoteMicrosoft wants us to "Imagine life without walls"...
I say, "If there are no walls, who needs Windows?"


Useful Links:
Online Manual!
How to Help us Help you
Search
Settings Repair Tool


Sarge

Quote from: SA(^_^)Mi on May 26, 2008, 06:17:21 PM
teşekkürler Harzem Bey

SA(^_^)Mi, this is an English language board. The Turkish language board is located at: Türkçe (Turkish)

But I understand that you are saying "Thank you, Mr. Harzem" :)

    Please do not PM me with support requests unless I invite you to.

http://www.zeriyt.com/   ~   http://www.galeriashqiptare.net/


Quote
<H> I had zero posts when I started posting

Sami Ekici

Quote from: Sarge on July 05, 2008, 06:44:40 AM
Quote from: SA(^_^)Mi on May 26, 2008, 06:17:21 PM
teşekkürler Harzem Bey

SA(^_^)Mi, this is an English language board. The Turkish language board is located at: Türkçe (Turkish)

But I understand that you are saying "Thank you, Mr. Harzem" :)

Thats Oky. I'm Sorry..

Advertisement: