<서론>

Webwork 개발자가 webwork를 떠나 struts2로 이동하면서 webwork, ognl, sitemesh가 좀 버려진(?) 상태로 있었습니다.그러나 Apache 진영또는 오픈 소스쪽에서 webwork, ognl, sitemesh가 다시 생명력을 가지고 다시 일어서려는 분위기가 있다는 Trend를 알리고자 합니다.

요즘 Webwork 진영은 어떻게 돌아가는지 트렌드를 잠깐 소개하고자 합니다. 내용의 레퍼런스는 apache common dev 메일링 리스트입니다.

 

 

<본론>

Webwork(struts2), OGNL, Sitemesh를 세부적으로 보도록 하겠습니다.

1. Webwork-Struts2

Webwork는 장렬히 전사했지만,  Struts2에서 webwork의 모든 개념을 포함하여 열심히 만들어주고 있습니다.

최신 버전에 잘  release 되고 있습니다.

 

2. Webwork의 core library OGNL

OGNL은 Webwork MVC의 core library 였으며, 지금도 Struts2의 중요 라이브러리입니다.

또한 이 OGNL은 Apache 프로젝트 중의 일부이며 Spring Webflow까지 영향을 주는 라이브러리입니다.

2011년 초 OGNL에 마지막 남은 commiter(Lukasz)가 Apache Common 개발자 리스트에 도움을 요청하였습니다. 원래 개발자들도 ASF로 소스 이전하는 것에 대해서 찬성했지요. Common쪽에서 이를 지원하기 위해서 투표를 했고,  통과하였습니다.

 

- Apache Struts

- Apache Tapestry

- Apache Camel

- Apache Tiles

- MyBatis (formerly Apache iBATIS)

- Spring WebFlow.

 

ONGL은 incubator에서 벗어나 당당히 4.0 snpahost 버전을 공개하며 일어서고 있습니다.

Last Published: 01 November 2011  | Version: 4.0-SNAPSHOT

http://commons.apache.org/ognl/

 

 

3. Sitemesh

Sitemesh는 2까지 나오고 그동안 활동이 없었는데, Sitemesh 3가 나오게 되었습니다. 아직은 alpha 버전이긴 하지만, 조만간에 beta 릴리즈 계획이 있다고 합니다.  하지만 올해 초까지만 활동하고 지금은 조용한 상태입니다.

http://www.sitemesh.org/

Sitemesh 3의 특징 중 중요하게 바뀐 것은 다음과 같습니다.
- sitemesh의 내부 구조를 바꿔 기존보다 3배 이상의 속도와 메모리를 반 정도로 적게 쓸 정도로 함
- jsp나 velocity 없이 바로 static html로 생성할 수 있다.
- 기존보다 간단한 설정
 

4. 구글 트렌드 조사

 

webwork가 죽는 것 같았지만, 다시 살아나고 있는 트렌드입니다.

 


 

그리고, 중국진영에서 열심히 쓰고 있습니다.

 

 

 

OGNL은 여전히 힘을 잃고 있기는 하지만, 중국에서 장난아니게 사용되고 있음을 볼 수 있습니다.

 

 

 

 

<결론>

Webwork, Sitemesh, OGNL 오픈소스를 지원했던 OpenSymphony 가 사라졌지만, 그의 후예들이 계속 노력해서 새롭게 변화하고 있다는 것을 조사하면서 기분이 좋았습니다. 좋은 프레임웍은 계속 살아남는구나 하는 생각이 들었습니다.

최근에는 중국 사용자들이 OGNL에 많이 참여하고 있으며, 중국어 페이지를 개설하려는 움직임이 있으며 활발하게 제안하며 활동하고 있습니다.

그것을 보면서 어쩌면.. 중국 또는 아시아권에 의해서 webwork(struts2)/ognl/sitemesh 개발 붐이 일어날 수 있겠구나 하는 생각이 들었습니다. 

 

 

 

참고자료

 

http://wiki.apache.org/incubator/OGNLProposal

http://www.opensymphony.com/ognl/

https://github.com/sitemesh/sitemesh3/wiki

http://www.sitemesh.org/overview.html

Posted by '김용환'
,

2010년 7월 14일에 Struts2, webwork를 사용하는 웹 서버에 remote command 실행을 통해서 jvm을 종료시키게 하는 보안 공격을 오픈했다.
(참조 : http://sebug.net/exploit/19954/)

Webwork및 Stuts2 MVC Framework를 사용하는 서비스에서 아래와 같이 ParametersInterceptor를 사용하는 경우에 생길 숭 ㅣㅆ다.
<include file="webwork-default.xml" />
<interceptor-ref name="params" />


위의 링크에 있듯 아래와 같이 OGNL 문법을 이용하면, JVM이 exit 된다.


http://mydomain/MyStruts.action?('\u0023_memberAccess[\'allowStaticMethodAccess\']')(meh)=true&(aaa)(('\u0023context[\'xwork.MethodAccessor.den
yMethodExecution\']\u003d\u0023foo')(\u0023foo\u003dnew%20java.lang.Boolean("false")))&(asdf)(('\u0023rt.exit(1)')(\u0023rt\u003d@java.lang.Runtime@getRunti
me()))=1


잘못된 OGNL 문법이 ParamtersInterceptor에 전달되어 JVM 종료를 실행하도록 하는 것이다.

Struts2에서는 확인하고 ParametersInterceptor.java를 수정하였다.

http://svn.apache.org/viewvc/struts/struts2/trunk/xwork-core/src/main/java/com/opensymphony/xwork2/interceptor/ParametersInterceptor.java?r1=956389&r2=956388&pathrev=956389


+

/**
  * <!-- START SNIPPET: description -->
@@ -134,7 +134,8 @@ public class ParametersInterceptor exten
     Set<Pattern> acceptParams = Collections.emptySet();
     static boolean devMode = false;

-    private String acceptedParamNames = "[[\\p{Graph}\\s]&&[^,#:=]]*";
+    // Allowed names of parameters
+    private String acceptedParamNames = "[a-zA-Z0-9\\.\\]\\[_'\\s]+";
     private Pattern acceptedPattern = Pattern.compile(acceptedParamNames);

     private ValueStackFactory valueStackFactory;



원래 ParametersInterceptor.java의 소스에서의 param 패턴을 분석해보자  
(http://download-llnw.oracle.com/javase/1.5.0/docs/api/java/util/regex/Pattern.html)

[원래 소스]

[[\\p{Graph}\\s]&&[^,#:=]]*


1)  \p{Graph}  
     A visible character: [\p{Alnum}\p{Punct}]
     alphanumeric character && Punctuation: One of !"#$%&'()*+,-./:;<=>?@[\]^_`{|}~

 2) \s
    A whitespace character: [ \t\n\x0B\f\r]

3) &&
    Any letter except an uppercase letter (subtraction)

4) [^,#:=]

이렇게 나눠볼 수 있을 것이다.

읽어보면 space와 숫자문자와 ^,#:= 를 제외한 특수문자의 셋(zero or more time) parameter로 지원한다.


[수정된 소스] ; 언뜻 보면 [ ] 때문에 헛갈린다.

"[a-zA-Z0-9\\.\\]\\[_'\\s]+"
     =>
[a-zA-Z0-9\\.\\]\\[_'\\s]+

1) a-zA-Z0-9

2)\\.

3) \\]

4)\\[

5)
_'\\s]+

이렇게 분석해놔야 조금 이해가 되었다.

General하게 받지 않고, 특정 패턴만 들어오게 했다.

Webwork는 버려진지 오래되어서, 따로 패치는 안될 것 같다. (이래서 Strtus2의 미래가 불안하다. 담당 개발자 사라지면 버려지지 않을까? ) 대신 Struts2로 가서 패치는 했다.


하지만, 여기서 잘 봐야하는 문제는.. 기존의 Webwork 서비스에서는 잘 돌았는데, 패치 버젼 사용 및 위의 내용을 그대로 패치 이후에 문제가 생길 수 있다. 빠질 수 있는 패턴을 고민해야 봐야한다.

특히 특수 문자 쪽으로 봐야하는데..

기존에 파라미터에 - (bar)를 사용하고 있는데, 패치 이후로는 문제를 해결하지 못할 수 있다. 헐... 
Struts2 그냥 믿지 마시라.. 꼼꼼히 살펴볼 것.

-(bar)를 추가해서 적용할 필요가 있다.
"[a-zA-Z0-9\\.\\]\\[_'-\\s]+"

'Web service' 카테고리의 다른 글

Pro Spring 2.5 소스 코드  (0) 2010.09.25
REST 설명  (0) 2010.09.16
browser에서 request header를 수정할 수 있는 법  (0) 2010.08.24
구글 Closure  (0) 2010.08.24
[보안] SQL Injection 공격 막기 - 아파치 모듈 이용  (0) 2010.08.18
Posted by '김용환'
,

You may  meet java errors every day if you are a java developer. Especially if a lot of or critical error logs in web application get to meet, you will be panic. So, there is need to develop error log DB and error-collectiong log module.
I will introduce my idea about developing error log DB.
According to your company policies, methods are applied for error logging system.

Architecture of error logging system consists of
1) Error DB can be stored
2) Admin web application can show errors on error db
3) Java classes and log4j configuration to transfer logs to DB.



<Error DB>
In web application, there are many properties to save such as belows.
project-name, server-name, loginid(userid), access date-time, log level, url, form, cookie, referer, execpetionmessage 

You can specify those more concisely. For example, exceptionmessage is divided to head and body according to java.lang.Exception.

I made error log db, table. Specially I made indexing in mysql. And in mysql DB, I made a batch script to rotate log db.

#!/bin/sh
TODAY=`date -d "-1 day" +%Y%m%d`
TO_DELETE_DAY=`date -d "-30 day" +%Y%m%d`
mysql  -u userid -p password mysql db-schema-name << !


# rotate log table 
alter table lgt_logdata rename logdata_${TODAY}; 


drop table if  exists logdata_${TO_DELETE_DAY};

create table logdata (
  logid int(11) NOT NULL auto_increment,
  projectname varchar(30) ,
  servername varchar(20) ,
....
  KEY lgt_logdata_ix1 (projectname,loglevel)
)



<Error-collectiong>
Error-collecting log module is implemented by log4j in simple. You can change the properites to save several log-level like error, warning. So, you can make warning log DB as well.


Let us suppose to save the errors to mysql. 
<Log4j.xml>

<appender name="ERROR-OUT" class="org.apache.log4j.jdbcplus.JDBCAppender">
<param name="Threshold" value="ERROR"/>
<param name="dbclass" value="com.mysql.jdbc.Driver"/>
<param name="url" value="jdbc:mysql://in.log.google.com"/>
<param name="username" value="error"/> 
<param name="password" value="nobodynobodywantyou"/>
<param name="sqlhandler" value="com.google.kr.MySQLHandler"/>
<param name="Buffer" value="1"/>
</appender>


<logger name="com" additivity="false">
<level value="DEBUG"/>
            <appender-ref ref="ERROR-OUT"/>
</logger>


You have to save error-loging policy in your web application.
I think every logs have to store error log DB, so, I have policy to save all tomcat logs. Because every any kinds of errors can affect the performance of web application.

I have three policies to store the DB. I think those are very important to design error DB.
1. Using Interceptor in web work or struts2, web data such as url, form have to save MDC. (MDC is api of log4j framework)

Before web application meet java exceptions, the interceptor save the web information and after invoking action it checks the result of invoking action are failed(or throw exception). If the action throws the exception, those errors will sqlhandler (ERROR-OUT)

MDC.put("projectname", projectname);
MDC.put("cookie",cookie);

2. Use Servlet in web.xml. 

You may extend and implements extends javax.servlet.http.HttpServlet class. Through the implemented class to handle error, you can store errors.

<servlet>
<servlet-name>errorHandler</servlet-name>
<servlet-class>com.google.kr.ErrorHandlerServlet</servlet-class>
</servlet>
3. Adding some fuctions to sqlhandler.
Most of error cases occur in calling action from users, but in some case internal web application invoker can make errors. For example batch or cache or scheduling based on Thread could make fault, but belows method can not include saving error logs.
And then, when you implement sqlhandler, you can add those.
You've got to adds some exceptional case on the sqlhandler.

import org.apache.log4j.jdbcplus.JDBCSqlHandler;
public class ErrorHandler implements JDBCSqlHandler {
...
}


<web applicatiion for error log>
You can show the errors stored in DB in simple.

Posted by '김용환'
,