SV.AUTH.BYPASS.MUST
不正確な認証
loggedIn クッキーをチェックして、そのユーザーが既にログインしているかを確認するユースケースもありえます。ログインしていない場合、そのコードはユーザーが指定したユーザー名とパスワードを使用して認証を実行します。正常に実行されると、コードはユーザーが既にログインしていることを「記憶」するように loggedIn とユーザーのクッキーを設定します。SV.AUTH.BYPASS.MUST チェッカーは、ユーザー認証に使用されている方法が十分でかつ認証がバイパスされないものであるかどうかを検証します。
このチェッカーは、本体で .getParameter() または .get() のいずれかと一緒に "userName" と "password" が使用されている場合に欠陥を報告します。
脆弱性とリスク
アクターがその特定のアイデンティティを主張していても、その主張の正しさがソフトウェアで (十分に) 証明されない場合、この脆弱性は意図しないアクターへのリソースまたは機能の露出につながりかねません。この脆弱性があると、攻撃者に機密情報が漏れたり、任意のコードを実行するチャンスを与えたりする可能性があります。
脆弱コード例 1
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
Map<String, String> result = new HashMap<>();
Cookie[] cookies = request.getCookies();
if (cookies != null) {
for (Cookie cookie : cookies) {
result.put(cookie.getName(), cookie.getValue());
}
}
if (result.isEmpty() || ! (result.get("loggedIn") != null && "true".equals(result.get("loggedIn")))) {
if (! AuthenticateUser(request.getParameter("userName"), request.getParameter("password"))) { //both username and password
System.out.error("Error: you need to log in first");
}
else {
// Set loggedin and user cookies.
Cookie loggedIn = new Cookie("loggedIn", "true");
Cookie userName = new Cookie("userName", request.getParameter("userName"));
}
}
}
この例では、Klocwork は 10 行目で「クッキー loggedIn の使用は認証のバイパスを引き起こす可能性がある」という SV.AUTH.BYPASS.MUST 欠陥を報告します。
修正コード例 1
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
if (! AuthenticateUser(request.getParameter("userName"), request.getParameter("password"))) { //both username and password
System.out.error("Error: you need to log in first");
}
else {
// Set loggedin and user cookies.
Cookie loggedIn = new Cookie("loggedIn", "true");
Cookie userName = new Cookie("userName", request.getParameter("userName"));
}
}
修正されたこの例では、認証のバイパスに使用される可能性のあるクッキーが使用されていないため、Klocwork はもはや欠陥を報告しません。
脆弱コード例 2
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
Map<String, String> result = new HashMap<>();
Cookie[] cookies = request.getCookies();
if (cookies != null) {
for (Cookie cookie : cookies) {
result.put(cookie.getName(), cookie.getValue());
}
}
if (result.isEmpty() || ! (result.get("loggedIn") != null && "true".equals(result.get("loggedIn")))) {
if (! checkUser(request.getParameter("userName"))) { //only username
System.out.error("Error: you need to log in first");
}
}
}
この例では、Klocwork は 10 行目で「クッキー loggedIn の使用は認証のバイパスを引き起こす可能性がある」という SV.AUTH.BYPASS.MUST 欠陥を報告します。
修正コード例 2
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
if (! checkUser(request.getParameter("userName"))) { //both username and password
System.out.error("Error: you need to log in first");
}
else {
// Set loggedin and user cookies.
Cookie loggedIn = new Cookie("loggedIn", "true");
Cookie userName = new Cookie("userName", request.getParameter("userName"));
}
}
修正されたこの例では、認証のバイパスに使用される可能性のあるクッキーが使用されていないため、Klocwork はもはや欠陥を報告しません。
関連チェッカー
セキュリティトレーニング
Secure Code Warrior が提供しているアプリケーションセキュリティトレーニング教材。