/    Sign up×
Community /Pin to ProfileBookmark

I have some forms that I need to make more secure. I’v found that if you put the below code into one of the form fields, it executes the script when the page loads again displaying this in the form field. How can I not allow this type of thing?

Javascript code that got executed;

‘;alert(‘XSS’)//”;alert(‘XSS’)//</SCRIPT>!–<SCRIPT>alert(‘XSS’)</SCRIPT>=%26{}

Thanks

to post a comment
PHP

6 Comments(s)

Copy linkTweet thisAlerts:
@LiLcRaZyFuZzYNov 02.2005 — how is the form processed?
Copy linkTweet thisAlerts:
@NogDogNov 02.2005 — You could use [url=http://www.php.net/htmlentities]htmlentities()[/url] when you output the data so that the html tags are not output as such.
Copy linkTweet thisAlerts:
@jrthor2authorNov 03.2005 — Ok, I got htmlentities to work, thanks. Now I have another issue. If I enter something like the below code in a city search box on a form, it returns me a list of all cities that begin with N or s. How can I stop this?

N%' or Insrp_prop_cty Like 's%

Thanks again!
Copy linkTweet thisAlerts:
@NogDogNov 03.2005 — Assume the name of the form field with the search value is called "search":
[code=php]
$search = $_POST['search'];
if(ini_get("magic_quotes_gpc"))
{
$search = stripslashes($search);
}
$search = mysql_real_escape_string($search);
# now $search is ready for use in a query.
[/code]
Copy linkTweet thisAlerts:
@jrthor2authorNov 03.2005 — We are not using mysql at all. We call our Oracle database with straight SQL commands. What is this: if(ini_get("magic_quotes_gpc"))??
Copy linkTweet thisAlerts:
@NogDogNov 03.2005 — Replace mysql_real_escape_string with addslashes() for non-mysql use.

The ini_get() expression is checking to see if "magic quotes" is turned on, which escapes all quotes from the form input. I was doing that to make sure the mysql_real_escape_string() (or addslashes) did not "double escape" quotes in the input.
×

Success!

Help @jrthor2 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.6,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...