public void checkAdminCookie(HttpServletRequest request){
for (Cookie cookie : request.getCookies()) {
if (cookie.getName().equals("admin") &&
cookie.getValue().equals("true"){
setAdminMode();
}
}
}
Including client side input validation
Really!
Don't rely on a thin perimeter of security
Have overlapping controls
Not everyone needs access to the nuclear arsenal
public void updateUser(String userSuppliedName, long userID){
String query = "UPDATE users SET name='" +
userSuppliedName + "' WHERE id=" + userID;
getJdbcTemplate().execute(query);
}
SELECT email FROM users WHERE username='$userInput';
Input: jon
SELECT email FROM users WHERE username='jon';
Input: hack'; UPDATE users SET passwd='abc' WHERE username='admin
SELECT email FROM users WHERE username='hack'; UPDATE users SET passwd='abc' WHERE username='admin';
Exploting a basic SQLi vulnerability
public void updateUser(String userSuppliedName, long userID){
String query = "UPDATE users SET name='" +
userSuppliedName + "' WHERE id=" + userID;
getJdbcTemplate().execute(query);
}
public void updateUser(String userSuppliedName, long userID){
String query = "UPDATE users SET name=? WHERE id=?";
getJdbcTemplate().update(
query, new Object[]{userSuppliedName, userID});
}
Exploting a normal reflected XSS vulnerability
Integrity and confidentiality are gone!
Installing malware on the user's computer
Strict validation is very effective!
Blacklisting (< > " ' ...) less so, but still useful
Lisa O'Reilly?
Encoding the data so that command characters are "disarmed"
http://yoursite.com/hello.jsp?name=<script>alert('This is XSS');</script>
Vulnerable, unescaped use of input:
In jsp: <p>Hello, ${name}</p>
Resulting html: <p>Hello, <script>alert('This is XSS');</script></p>
Safe, html-escaped use of input:
In jsp: <p>Hello, <c:out value="${name}"/></p>
Resulting html: <p>Hello, <script>alert('This is XSS')</script></p>
The challenge: escape for the correct context, everywhere
User input stored on the server, then included in html
Scripts reading user data and then
writing html(.innerHtml, .outerHtml, .html(), document.write, createElement
)
or executing (eval(), setInterval(), setTimeout(), location.replace
)
http is stateless
JSESSIONID=y2rzQ9JRgrP9J3vCX3phJ1XJbDdgLqgDSBYM7qBRGSDQr7PdnF1B!-1147520699;
1. Transport layer encryption (TLS/SSL)
2. Cookie flags:
httpOnly - avoid access through XSS
secure - avoid clear text transmission
3. Re-authentication
Predictable requests to a site can be forged
<form action="account.jsp">
<input type="hidden" name="csrf_token"
value="FRUjQxPbyqmTtuXxip2tOWEqLFd">
Username: <input type="hidden" name="username" value="user">
Password: <input type="password" name="password">
...
</form>
Do not trust user input!
SQLi
XSS
Session issues
CSRF
These slides are available at jonare.github.com/jz12/
owasp.org OWASP Broken Web Applications Project OWASP Top 10
SQLi The SQL Injection Knowledge Base
XSS Try XSS yourself at Erlend Oftedal's insecurelabs.org An overview of DOM XSS Attack vectors at html5sec.org Attack vectors at ha.ckers.org
Tools OWASP Zed Attack Proxy (ZAP) Firefox add-on Tamper Data
Blog The .NET n00b - Security through http reponse headers troyhunt.com