본문 바로가기
Web Security/SecureCoding

보안결정을 신뢰할 수 없는 입력 값에 의존

by KkingKkang 2023. 2. 1.

- 응용프로그램이 외부 입력값(쿠키, 환경변수, 히든필드 등))에 대한 신뢰를 전제로 보호메커니즘을 사용하는 경우

공격자가 입력값을 조작할 수 있다면 보호메커니즘을 우회할 수 있게 된다. 

 

  • 시스템의 상태정보와 중요한 정보는 서버에만 저장한다.
  • 중요한 정보를 클라이언트 쪽에 저장할 경우, 암호화와 무결성 검사를 거친 데이터만 저장되도록 한다. 
  • 외부입력과 관련된 검사가 자바스크립트를 통해 브라우저에서 이루어지더라도, 서버측에서 재검사를 한다.

 

cookie 말고 session으로 

안전하지 않은 코드 ▼

<%
String username = request.getParameter("username");
String password = request.getParameter("password");
if(username == null || password == null || !isAuthenticatedUser(username, password)) {
	throw new MyException("인증 에러");
}
Cookie userCookie = new Cookie("user",username);
Cookie authCookie = new Cookie("authenticated","1");

response.addCookie(userCookie);
response.addCookie(authCookie);
%>

안전한 코드 ▼

<%
String username = request.getParameter("username");
String password = request.getParameter("password");
if(username == null || password == null || !isAuthenticatedUser(username, password)) {
	throw new MyException("인증에러");
 }
 //사용자 정보를 세션에 저장한다.
 HttpSession ses = new HttpSession(true);
 ses.putValue("user",username);
 ses.putValue("authenticated","1");
 %>

 

 

반응형

'Web Security > SecureCoding' 카테고리의 다른 글

XSS와 lucy xss Sax filter  (0) 2024.01.19
JS) SQL 삽입  (0) 2023.02.24
SQL 삽입 공격 : Hibernate  (0) 2023.02.01
안전하지 않은 리플렉션  (2) 2023.02.01
JS) eval() 을 사용하면 안되는 이유  (0) 2023.02.01

댓글