Closed
Description
Considering that sanitizing user input, especially from the internet, is important for preventing javascript, sql and other injections, it would be nice if in defining an "insert" or "update" statement in xml or by annotation, I could specify a processor/sanitizer that would validate/cleanup input values.
It could possibly be specified as follows:
<insert id="insertExample1" sanitizerType="org.example.NoJavaScriptSanitizer">
insert into table a (col1, col2)
values (#{col1},#{col2:sanitizer=org.example.SafeHtmlSanitizer}</sanitizer>
</insert>
<insert id="insertExample2" sanitizerMap="insertExample2SanitizerMap">
insert into table b (col1, col3)
values (#{col1},#{col2},#{col3})
</insert>
<sanitizerMap id="insertExample2SanitizerMap">
<sanitizer type="org.example.SafeHtmlSanitizer" inputs="col2,col3"/>
<sanitizer type="org.example.NoJavaScriptSanitizer"/>
</sanitizerMap>
@Insert("insert into table a (col1, col2)
values (#{col1},#{col2:sanitizer=org.example.SafeHtmlSanitizer}", sanitizer=NoJavaScriptSanitizer.class);
public int insertExample3(@Param("col1") int col1, @Param("col2") String col2 )
The sanitizer would be called when resolving the values of the #{...} tokens before calling setNonNullParameter() for the value type handler.
The sanitizerType/sanitizerMap would work similar to the resultType/resultMap functionality.