Hi all,
i wondered how secure the automatic data binding is, when using domain objects directly as command objects (a very usefull feature together with hibernate).
If i have a jsp-form which uses <bind>-tags to bind certain fields of the command object to form fields, then all the command objects properties will be set automatically upon form submit. Thats fine so far.
But what happens if a user manipulates the form submit, e.g. by adding additional form fields in the html code (which try to set properties on the command object, which were not bound with the <bind>-tag)?
As i could not find definitive information on this, i made an experiment with the petclinic sample from the current Spring 1.1.1:
The ownerFrom.jsp for adding a new owner includes the firstName.jsp for the respective form field.
As expected the first name is set in the command object upon submission.Code:firstName.jsp (with binding): <%@ include file="/WEB-INF/jsp/includes.jsp" %> <B>First Name:</B> <spring:bind path="command.firstName"> <FONT color="red"> <B><c:out value="${status.errorMessage}"/></B> </FONT> <BR><INPUT type="text" maxlength="30" size="30" name="firstName" value="<c:out value="${status.value}"/>" > </spring:bind> <P>
If i remove the <bind>-tags the jsp looks like this:
When submitting this form the firstName is still set on the command object. The only (expected) change i noticed is that on invalid submits the current value of firstName is not kept in the form.Code:firstName.jsp (without binding): <%@ include file="/WEB-INF/jsp/includes.jsp" %> <B>First Name:</B> <FONT color="red"> <B><c:out value="${status.errorMessage}"/></B> </FONT> <BR><INPUT type="text" maxlength="30" size="30" name="firstName" value="<c:out value="${status.value}"/>" > <P>
So, using this example, my question is: Shouldn't Spring check that only those form fields are set on the command object, which were bound with the bind-tag?
If i use my domain objects as command object, then this seems to me like a big security hole, as any user could potentially change any property that can be reached by the command objects associations.
The DataBinder class has a method setAllowedFields() which could be used, but shouldn't Spring do this automatically?
I am looking forward to your answers, am i wrong with my assumptions?
Thanks a lot!
Sebastian
BTW: setting sessionForm=true did not change this... just an idea...


Reply With Quote