background: I encoded the ActionSupport struts2 class with ModelDriven. This is a hibernate / spring web application using OSIV and attached objects in a view (JSP).
Today I received this letter from an architect βpunishingβ me for placing an object that had a link to an attached object on struts2 rack through ModelDriven<E> . Is he right or what? Obviously, this is a serious thing that I am doing, but I do not follow what he says, and I really do not want to accept his offer and visit him at my table after that. Oh boy. Time to change your career.
--- from the architect ---
Billy, as we said earlier, you still make the same mistakes in your code over and over again. This is the fourth time you have made this mistake, and I am concerned about the quality of your work. It is one thing to do this once or even twice, but after the fourth time, I wonder if you can understand what I am saying. The following will set this out for you. If you do not receive it after reading this letter, go to my desk and we will consider it. This needs to be stopped immediately, and I want all your code reorganized by the end of the day, fixing this error. If any code bleeds into production, we will have a serious security problem at our fingertips. Also note that I am copying Dave to this so that a proper reprimand can be issued. I will also recommend Dave that you move from a Level III developer to Level II. Read the following and please study it and reformat all your code as I pointed out.
About binding objects:
When the Struts2 action class is marked with the ModelDriven interface, the model will be bound to form elements in the HTML page. For example, if the HTML form has a field called userName, and the action class is defined as:
public class UserAction extends ActionSupport implements ModelDriven
And the UserModel is a POJO as follows:
public class UserModel { private String userName; public String getUserName() { return userName; } public void setUserName(String userName) { this.userName = userName; } }
When the form is submitted while the action contains an instance of UserModel, struts2 will associate the userName field with UserModel.userName, automatically filling in the value.
However, this simplicity is expensive for malicious users. If an object is declared as ModelDriven, the end user viewing the user who has access to the model graph through model installers. Take this example, for example:
public class UserAction extends ActionSupport implements ModelDriven
and...
public class UserModel { private String userName; private UserEntity userEntity; public String getUserName() { return userName; } public void setUserName(String userName) { this.userName = userName; } pubic UserEntity getUserEntity() { return userEntity; } }
and...
@Entity public class UserEntity { private String password; public String getPassword() { return password; } public void setPassword(String password) { this.password = password; } }
assuming an OSIV pattern is being used, and a UserEntity object is attached.
A damned user with little knowledge or time on hand can:
/myform?userName=billy&userEntity.password=newpassword
Assuming that the Entity is saved at the end of the session, the above results change the Billy password.
Point, graph objects available!
When using ModelDriven and using an alternative is a terrible approach, you have to identify fine-grained models that fit in the cost price and then copy from the model to the target before sending a response and resolving the transaction.