This page is to discuss the possible options of integrating HDIV with Struts.
SPI or native integration?
Matt Raible: HDIV seems to solve a problem that most web application developers don't know they have. By "natively", I mean it's part of the core and you can't make your application less secure by ripping it out. It is Apache licensed after all. If rolling it into the core isn't an option, it would be nice if it was easier to integrate. Instead of requiring new tag libraries, it'd be nice if tag libraries (and Velocity/FreeMarker macros) were "HDIV aware". If an HDIV JAR/Plugin is on the classpath - use it.
Paul Benedict: I wouldn't want to fork the project because I am not a security expert. I couldn't maintain it well even though I want to integrate it. Also, I don't know if HDIV has aspirations outside of Struts which would make an SPI much more palatable. I am not strongly in favor of belonging to the core. I think the feature should be optional, but I wouldn't also object if it was put of the core with the option to turn on/off.
Martin Cooper: Which security package(s) would you want to work with in addition to HDIV? I firmly believe that you need at least two candidates in order to successfully design an SPI. Otherwise you run a very high risk of designing an SPI that can really only be successfully used by the one candidate you designed it around.
HDIV team: We think it's better to use a SPI. From our point of view the SPI it's an extension point that could be interesting for many projects, not only for security projects. For example if you use webflow in a Struts application you have to add flow execution key parameters by hand and that could be easily solved by implementing a SPI.
Of course, if we use the SPI it's not necessary to extend struts' tld making it easier to integrate HDIV.
In addition to that if you use the SPI you can activate or desactivate updating Struts configuration. By default Struts can use an empty implementation of the SPI.
HDIV can be very useful for many applications but not for others. For example if you have a public web page where it's necessary to be indexable, you shouldn't use HDIV because all links are dynamic and related with web session (the same problem of JSF but in this case you can desactivate it).
About Paul Benedict's comment ("I don't know if HDIV has aspirations outside of Struts which would make an SPI much more palatable"), the target of HDIV is the integration with all web frameworks that need this type of security functionalities. So far we have developed HDIV versions for:
- Struts 1
- Struts 2
- Spring MVC
- WebWork (not published)
- Stripes (not published)
- JSF (not published)
Some of them are still under development, but they will be published in a few months. In consecuence, it will be useful if the SPI it's generic and works with all web frameworks. But thinking about the implementation and library dependencies maybe it would be better if each framework had it's own interface, similar to interceptors concept in many frameworks but in this case related with tag libraries. Anyway, we could create a first release supporting commented frameworks.
Martin Cooper: Please re-read my comment. I am not arguing against an SPI per se. My point is that, without some other security framework in mind in addition to HDIV, it is very unlikely that you will be able to design an SPI that can successfully be used by any other security framework.
Also, given the list of frameworks that you already support, don't you already have an internal API, so that the bulk of your code is common for all frameworks, and you just have a small shim to specialise it for each framework? If that's the case, then how much value is there in having a shared SPI just within Struts? You really need all of the frameworks to implement that SPI, not just Struts, in order to get rid of your per-framework shims, in which case you really want to engage all of the frameworks in the SPI design, not just the Struts team.
HDIV team: From our point of view, although we find interesting to define a common interface for all the frameworks, our primary goal is to add new extension points to Struts' API so that Struts' users can use it in a transparent way, without having to copy any source code.
The real problem is similar to what happens in Struts 1 with the RequestProcessor: when you need to intercept a request's life cycle, many times you are forced to extend the RequestProcessor and copy parts of the existing code next to the extension. This problem was solved in Struts2, because each step of the life cycle is implemented by a different interceptor.
Actually, we want to add extension points to the HTML creation process.
When implementing HDIV for Struts, we had to extend tags and copy parts of the Struts' source code in order to fulfil HDIV's objectives. For us, these are the main reasons why an interface should be created:
- Avoid having to extend tags and copy source code. Also avoids creating a new version for the extension for each Struts' version.
2. Provide extension points that could be used by any framework.
3. Eliminate the direct dependency between Struts and HDIV.
If we integrate HDIV natively in the tags, without using an interface, we eliminate an extension point that could be required by other frameworks or by Struts itself. Nowadays, we don´t know who and how will require this interface (the automatization of the webflow's flow execution key could be an example), but from a designer point of view it is always better to define an interface that could change from version to version.
There should be two different implementations of this interface: the one provided by HDIV and the one provided by Struts. Struts' implementation would keep the current tag behaviour and HDIV's one would add security functionalities.
In our opinion, HDIV's implementation should be configured by default in order to make the application safer. If the developers don't require HDIV they could modify the configuration and use the empty implementation provided by Struts.
So, although we find using an interface a better solution, we don´t have any problem if the final decision is to include it natively in the code.
Ted Husted: It's unusual that a feature such as this comes without penality. If HDIV were native, what would be the performance cost? Complexity cost?
HDIV team: In our opinion the performance offered by HDIV is acceptable and it could be activated by default, but we have to take into account that it generates a problem with the pages indexation (all links are dynamic and related with web session). Consequently we think it's better if the HDIV activation it's optional.
Another discussion is if it has to be activated by default or not. From a security point of view it's better if HDIV is activated by default. We agree with Matt Raible when he says that HDIV "solves a problem that most web application developers don't know they have". In our experience we have seen that even experimented developers don't know they have.
For more information about HDIV performance see hdiv-performance.pdf
Martin Cooper: How does HDIV's editable content validation interact with the validation mechanisms that we already have built into Struts? Is someone using HDIV with Struts going to be writing their validations using HDIV's format, Commons Validator's format, or both?
HDIV team: Editable data validation offered by HDIV it's integrated with struts’ validator. HDIV creates validation errors within HDIV's validation filter and they are added within HDIV RequestProccessor. The errors generated by HDIV are generated with the same format of Struts and they are visualized in the same way as usual errors using Struts tags ( html:errors,logic:messagesPresent, etc.).
For more information about it see HDIV reference (chapter-126.96.36.199.2).
Martin Cooper: How much of the functionality of HDIV is only available for people using JSP with tag libraries? If I'm using Velocity, or not using server-side presentation at all, how much of HDIV do I lose?
HDIV team: The core API of HDIV (hdiv-core) is not related with a concrete technology and it’s possible to use it with any technology. Although we haven’t implemented it for Struts 1 the integration of Velocity and Freemarker it's included in Struts 2 version, see Struts 2 example application, within (struts2-showcase-2.0.x) ui-tags section.
Martin Cooper: If I am not using any server-side presentation technology at all, which parts of HDIV do I lose? Which can I still use?
HDIV team: If no presentation framework is used (or the one used is not supported by HDIV), the only way to use HDIV is to consume the base API offered by HDIV core (hdiv-core). That is, the program which generates the HTML code should consume the methods offered by the IDataComposer interface.
Obviously, in this case the use of HDIV is not transparent as it is when we use the extended tags. Anyway, the validation phase made by the HDIV filter doesn't change in any case.
SPI (ParameterProcessing) Integration
HDIV team: As we mentioned earlier, from our point of view it is more adecuate to integrate HDIV with Struts via SPI due to the following reasons:
- We avoid a direct dependency between Struts and HDIV.
- Offers an extension point for Struts tags that can be used for other projects apart from the ones related with security or HDIV.
The new extension point provided by the SPI offers these functionalities:
- Add new parameters to forms and links
- Modify the value of the parameters
- Modify the name of the parameters
The SPI could be used for both Struts 1 and Struts 2. Being defined in a so high level it could be used for any web framework, although this
would be a secondary objective.
In order to support the SPI option, we have developed the following software components:
2. Struts 1.3.8 tags' version using the SPI
3. Two implementations of the SPI: empty and HDIV's implementation
4. Web application using these new components: struts-examples
The SPI, the new version of SPI-consuming tags and the empty SPI implementation would be part of Struts, without any HDIV dependency. In the case of Struts 2, a new version of tags must be implemented. We could implement it if necessary. As an additional information, we describe more deeply each of the developed components:
It is consumed by the HTML tags in order to offer extension points and extend tag's core behaviour. Thus, we avoid extending each tag separately. The name of the SPI is ParameterProcessing and this is its definition:
Source code: struts-core-1.3.8-ParameterProcessing-sources
2.Struts 1.3.8 tags' version using the SPI
We have modified Struts 1.3.8 HTML and LOGIC (redirect and forward) tags by adding calls to the SPI methods. We have implemented tags so that each time the attributes "name" or "value" need to be rendered they call SPI methods which process these values and obtain the processed value. Let's see an example with the tag "hidden". Keep in mind that this tag extends BaseFieldTag class which renderizes the HTML of the hidden field.
We always invoke methods from the SPI to obtain the values of the attributes "name" and "value" using processName() and processValue() methods. This is the main rule that we have followed for all the tags. As we can see in the definition of the SPI, there are methods to be invoked in other cases, for example in the beginning and in the end of a form or when generating an url; For these cases "form" and "link" tags have been implemented. Let's see the implementation of the tag "form":
In this case, we invoke processStartForm method to get the value for the "action" attribute in the form. And before the end of the form, we invoke getExtraFormParameters method to get the extra parameters to be added to the form. For instance, parameters for controlling the application's flow like flowExecutionKey in Spring Web Flow, random token to avoid CSRF attacks, and _HDIV_STATE parameter to guarantee integrity and confidentiality.
Source code: struts-taglib-1.3.8-ParameterProcessing-sources
3. Two implementations of the SPI
- empty (EmptyParameterProcessing): it maintains the Struts' present behaviour.
- HDIV (HDIVParameterProcesing): it guarantees data integrity and confidentiality.
In order to configure the SPI implementation, we must define the name of the class in the parameterProcessingClass attribute of the controller. Thus, the SPI implementation to use is defined for each module, making it possible to define different implementations for different modules. By default, if we don't define any value for this new attribute, the HDIV’s implementation will be used, which guarantees data integrity and confidentiality.
- struts-config-1_3.dtd file has been modified by adding the new "parameterProcessingClass" attribute.
See the example in point 4 to get more information about this configuration.
ActionServlet: The servlet has been modified to make it create a new instance of the SPI for each request made using the class defined in the controller.
4. Web application using these new components: struts-examples
We have configured the struts-examples application ( struts-examples-1.3.8.war )provided with the Struts 1.3.8 distribution to make it use different SPI implementations.
- Default SPI configuration: No implementation has been configured for “/exercise”, “/upload” and “/hdiv” modules. This means that SPI’s default implementation (HDIVParameterProcessing) will be used, which guarantees data integrity and confidentiality.
- We have configured for “/validation” and “/attacks” modules SPI's empty implementation to maintain Struts' present behaviour.