In Strategy Web, to prevent a CSRF attack, you can enable
validateRandNumin the
sys_defaults.xmlfile by changing its value to 1. This setting appends a dynamic token to each request made that is unique to the user session. As a result, if a link is opened without a valid token, an error is returned.
CSRFConfirmationPageComponentImplclass.

getPageSourcemethod provided by
CSRFConfirmationPageComponentImpl.
TagsFactoryinstance:
TagsFactory tf = TagsFactory.getInstance();
Tag messageDiv = (Tag) tf.newTag(EnumHTMLTags.TAG_NAME_DIV);
MarkupOutput:
MarkupOutput tempOut = WebBeanFactory.getInstance().newMarkupOutput(); messageDiv.render(tempOut);
MarkupOutto a string and return it:
String finalStringOutput = tempOut.getCopyAsString();
An example of the custom class may look similar to the following:
public class CSRF_Update_HREF extends CSRFConfirmationPageComponentImpl {
public CSRF_Update_HREF() {
super();
}
@Override
public String getPageSource() {
String originalMessage = super.getPageSource();
// Using TagsFactory https://www2.Strategy.com/producthelp/Current/WebAPIReference/com/MicroStrategy/web/tags/TagsFactory.html
TagsFactory tf = TagsFactory.getInstance();
Tag messageDiv = (Tag) tf.newTag(EnumHTMLTags.TAG_NAME_DIV);
// Create a new <span> tag which holds custom text
Tag spanContent = (Tag) tf.newTag(EnumHTMLTags.TAG_NAME_SPAN);
spanContent.addTextChild("This is a CSRF Error please click the link.");
messageDiv.addChild(spanContent); // Add <span> text to the return div
// Current path, ex: http://sup-002222.labs.Strategy.com:8080/MicroStrategy/servlet/mstrWeb
String currentPath = getAppContext().getServletPath();
// Create a new <a> tag
AnchorTag anchortag = tf.newAnchorTag();
anchortag.setAttribute("href", "http://www.google.com");
anchortag.setAttribute("target", "_blank");
anchortag.addTextChild(currentPath); // This provides the text for the anchor tag
messageDiv.addChild(anchortag); // A new <a> tag to return <div>
MarkupOutput tempOut = WebBeanFactory.getInstance().newMarkupOutput();
messageDiv.render(tempOut);
String finalStringOutput = tempOut.getCopyAsString();
return finalStringOutput;
}
}
pageConfig.xmlfile to point to the new source.
pageConfig.xmlfile (located at
/WEB-INF/xml/pageConfig.xml) and place it in your plugin at the same location (
[plugin_name]/WEB-INF/xml/pageConfig.xml).
<framework>
<pages>
<page name="CSRFConfirmation" class="customclasses.components.CustomCSRFConfirmationPageComponentImpl" >
</page>
</pages>
</framework>
The example provided in this article is provided “as-is” to the user and assumes that the user:
This customization is provided as a convenience to Strategy users and is only directly applicable to the version stated. While this code may apply to other releases directly, Strategy Technical Support makes no guarantees that the code provided will apply to any future or previous builds. In the event of a code change in future builds, Strategy Technical Support makes no guarantee that an updated version of this particular customization will be provided. In the event of a code change in future builds, Strategy may not be able to provide additional code on this matter even though this customization is provided at this time for this specific build. For enhancements to this customization or to incorporate similar functionality into other versions, contact your Account Executive to inquire about Strategy Consulting assistance.