NShiftKey-Rule-Guide logo NShiftKey-Rule-Guide

1. Vulnerability Description

URL Redirect

(Normal) https://www.example.com/function.jsp?redirect_url=comickr://agreeTermSuccess&cancel_url=comickr://agreeTermFailure

(Attack-URL Redirect) https://www.example.com/function.jsp?redirect_url=comickr://agreeTermSuccess&cancel_url=http://hacker.com/

URL Forward

For example, suppose there is an administrator menu page with the following address, and the page displays “You do not have access authority when access is controlled by an unauthorized user.

http://www.example.com/admin.jsp
An attacker will make the following request to access a restricted administrator menu page and will be able to access the administrator menu page if the fwd argument is not verified.
http://www.example.com/function.jsp?fwd=admin.jsp

[ picture 1. The difference between Foward and Redirect ]

[ picture 2. url redirect Example of vulnerability ]

2. How to check vulnerability

3. Vulnerability Countermeasure

Domain/page does not need to be changed

When a domain/page is variable

4.Sample Code

......
String id = utils.nvl((String)session.getValue("id"));
String bn = utils.nvl(request.getParameter("gubun"));
String rd = utils.nvl(request.getParameter("redirect"));
if (id.length() > 0) {
    String sql = "select level from customer where customer_id = ?";
    conn = db.getConnection();
    pstmt = conn.prepareStatement(sql);
    pstmt.setString(1, id);
    rs = pstmt.executeQuery();
    rs.next();
    if ("0".equals(rs.getString(1)) && "01AD".equals(bn)) {
        response.sendRedirect(rd);
        return;
    }
} else {
    if ("01AD".equals(bn)) {
    response.sendRedirect(rd);
    return;
    }
}
......
......
String allowedUrl[] = {"/main.do", "/login.jsp", "list.do"};
......
String rd = utils.nvl(request.getParameter("redirect"));
try {
    rd = allowedUrl[Integer.parseInt(rd)];
} catch(NumberFormatException e) {
    return "It's a wrong approach.";
} catch(ArrayIndexOutOfBoundsException e) {
    return "It's a wrong input.";
}
if (id.length() > 0) {
......
 if ("0".equals(rs.getString(1)) && "01AD".equals(bn)) {
    response.sendRedirect(rd);
    return;
 }
} else {
 if ("01AD".equals(bn)) {
url = 'http://test.com/aaa/bbb?cccc'
url = decodeURIComponent(url)
 
u = new URL(url)
 
if (u.protocol !== 'http:' && u.protocol !== 'https:')
{
    alert("error");
}
 
//naver.com, *.naver.com
if(! u.hostname.match(/(?:^|\.)naver\.com$/))
{
    alert("error");