Child pages
  • Grouper UI csrf xsrf prevention
Skip to end of metadata
Go to start of metadata

This is in Grouper 2.2 UI.  btw, Ive heard this does not work with IE8.

Logging

Set this in log4j.properties for enhanced logging

log4j.logger.edu.internet2.middleware.grouper.grouperUi.csrf.CsrfGuardLogger  = DEBUG

 

Legacy instructions

These instructions install OWASP CSRF guard in the Grouper UI.  These instructions are intended for Grouper v2.1, though it will probably work on v2.0, and could be adapted for previous versions as well.

1. Download the jar, note, this is from the mchyzer github clone
1.5. If you have Grouper UI v2.1.5 or less, then add this logging jar.  Note, remember on upgrade to remove this temporary jar.
2. Put the jar(s) in the UI WEB-INF/lib dir
3. Put this in the grouper UI web.core.xml (or web.xml if not building again), below all of the existing <filter> tags.

  <listener>
    <listener-class>org.owasp.csrfguard.CsrfGuardServletContextListener</listener-class>
  </listener>
  <listener>
    <listener-class>org.owasp.csrfguard.CsrfGuardHttpSessionListener</listener-class>
  </listener>

  <servlet>
     <servlet-name>OwaspJavaScriptServlet</servlet-name>
     <servlet-class>org.owasp.csrfguard.servlet.JavaScriptServlet</servlet-class>
  </servlet>

  <servlet-mapping>
     <servlet-name>OwaspJavaScriptServlet</servlet-name>
     <url-pattern>/grouperExternal/public/OwaspJavaScriptServlet</url-pattern>
  </servlet-mapping>

  <filter>
    <filter-name>CSRFGuard</filter-name>
    <filter-class>org.owasp.csrfguard.CsrfGuardFilter</filter-class>
  </filter>
  <filter-mapping>
    <filter-name>CSRFGuard</filter-name>
    <url-pattern>/*</url-pattern>
  </filter-mapping>
 

4. Create conf/Owasp.CsrfGuard.properties (which will go in WEB-INF/classes/Owasp.CsrfGuard.properties), which is the default properties file (extract from csrfguard.jar from META-INF/csrfguard.properties

5. Create conf/Owasp.CsrfGuard.overlay.properties (which will go in WEB-INF/classes/Owasp.CsrfGuard.overlay.properties)

org.owasp.csrfguard.Logger=edu.internet2.middleware.grouper.grouperUi.csrf.CsrfGuardLogger

org.owasp.csrfguard.TokenPerPage=false

org.owasp.csrfguard.action.Redirect.Page=%servletContext%/grouperExternal/public/csrfError.html


org.owasp.csrfguard.configuration.provider.factory=org.owasp.csrfguard.config.overlay.ConfigurationOverlayProviderFactororg.owasp.csrfguard.configuration.provider.factory=org.owasp.csrfguard.config.overlay.ConfigurationOverlayProviderFactory



org.owasp.csrfguard.unprotected.DefaultGrouper=%servletContext%/
org.owasp.csrfguard.unprotected.GrouperHome=%servletContext%/home.do
org.owasp.csrfguard.unprotected.GrouperDir=%servletContext%/grouper/*
org.owasp.csrfguard.unprotected.GrouperExternal=%servletContext%/grouperExternal/index.html
org.owasp.csrfguard.unprotected.GrouperExternalAppHtml=%servletContext%/grouperExternal/appHtml/*
org.owasp.csrfguard.unprotected.GrouperExternalPublic=%servletContext%/grouperExternal/public/*
org.owasp.csrfguard.unprotected.GrouperUi=%servletContext%/grouperUi/
org.owasp.csrfguard.unprotected.GrouperUiIndex=%servletContext%/grouperUi/index.html
org.owasp.csrfguard.unprotected.GrouperUiAppHtml=%servletContext%/grouperUi/appHtml/*
org.owasp.csrfguard.unprotected.GrouperI2mi=%servletContext%/i2mi/*
org.owasp.csrfguard.unprotected.GrouperScripts=%servletContext%/scripts/*
org.owasp.csrfguard.unprotected.GrouperIndex=%servletContext%/index.jsp
org.owasp.csrfguard.unprotected.GrouperOwaspJavascript=%servletContext%/grouperExternal/public/OwaspJavaScriptServlet

org.owasp.csrfguard.unprotected.GrouperStrutsbrowseStems=%servletContext%/browseStems.do
org.owasp.csrfguard.unprotected.GrouperStrutsbrowseStemsCreate=%servletContext%/browseStemsCreate.do
org.owasp.csrfguard.unprotected.GrouperStrutsbrowseStemsFind=%servletContext%/browseStemsFind.do
org.owasp.csrfguard.unprotected.GrouperStrutsbrowseStemsManage=%servletContext%/browseStemsManage.do
org.owasp.csrfguard.unprotected.GrouperStrutsbrowseStemsJoin=%servletContext%/browseStemsJoin.do
org.owasp.csrfguard.unprotected.GrouperStruts/browseStemsSubjectSearch=%servletContext%/browseStemsSubjectSearch.do
org.owasp.csrfguard.unprotected.GrouperStrutsbrowseStemsAll=%servletContext%/browseStemsAll.do
org.owasp.csrfguard.unprotected.GrouperStrutserror=%servletContext%/error.do
org.owasp.csrfguard.unprotected.GrouperStrutsfilterError=%servletContext%/filterError.do
org.owasp.csrfguard.unprotected.GrouperStrutshelp=%servletContext%/help.do
org.owasp.csrfguard.unprotected.GrouperStrutslogin=%servletContext%/login.do
org.owasp.csrfguard.unprotected.GrouperStrutslogout=%servletContext%/logout.do
org.owasp.csrfguard.unprotected.GrouperStrutspopulateAllGroups=%servletContext%/populateAllGroups.do
org.owasp.csrfguard.unprotected.GrouperStrutspopulateAssignNewMembers=%servletContext%/populateAssignNewMembers.do
org.owasp.csrfguard.unprotected.GrouperStrutspopulateChains=%servletContext%/populateChains.do
org.owasp.csrfguard.unprotected.GrouperStrutspopulateCopyGroup=%servletContext%/populateCopyGroup.do
org.owasp.csrfguard.unprotected.GrouperStrutspopulateCopyGroupToStem=%servletContext%/populateCopyGroupToStem.do
org.owasp.csrfguard.unprotected.GrouperStrutspopulateCopyOtherStemToStem=%servletContext%/populateCopyOtherStemToStem.do
org.owasp.csrfguard.unprotected.GrouperStrutspopulateCopyStem=%servletContext%/populateCopyStem.do
org.owasp.csrfguard.unprotected.GrouperStrutspopulateCreateGroup=%servletContext%/populateCreateGroup.do
org.owasp.csrfguard.unprotected.GrouperStrutspopulateCreateGroups=%servletContext%/populateCreateGroups.do
org.owasp.csrfguard.unprotected.GrouperStrutspopulateCreateStem=%servletContext%/populateCreateStem.do
org.owasp.csrfguard.unprotected.GrouperStrutspopulateDebugPrefs=%servletContext%/populateDebugPrefs.do
org.owasp.csrfguard.unprotected.GrouperStrutspopulateEditGroup=%servletContext%/populateEditGroup.do
org.owasp.csrfguard.unprotected.GrouperStrutspopulateEditGroupAttributes=%servletContext%/populateEditGroupAttributes.do
org.owasp.csrfguard.unprotected.GrouperStrutspopulateEditStem=%servletContext%/populateEditStem.do
org.owasp.csrfguard.unprotected.GrouperStrutspopulateFindNewMembers=%servletContext%/populateFindNewMembers.do
org.owasp.csrfguard.unprotected.GrouperStrutspopulateFindNewMembersForStems=%servletContext%/populateFindNewMembersForStems.do
org.owasp.csrfguard.unprotected.GrouperStrutspopulateGroupAsFactor=%servletContext%/populateGroupAsFactor.do
org.owasp.csrfguard.unprotected.GrouperStrutspopulateGroupMember=%servletContext%/populateGroupMember.do
org.owasp.csrfguard.unprotected.GrouperStrutspopulateGroupMembers=%servletContext%/populateGroupMembers.do
org.owasp.csrfguard.unprotected.GrouperStrutspopulateGroupPriviligees=%servletContext%/populateGroupPriviligees.do
org.owasp.csrfguard.unprotected.GrouperStrutspopulateGroupSummary=%servletContext%/populateGroupSummary.do
org.owasp.csrfguard.unprotected.GrouperStrutspopulateGroupTypes=%servletContext%/populateGroupTypes.do
org.owasp.csrfguard.unprotected.GrouperStrutspopulateIndex=%servletContext%/populateIndex.do
org.owasp.csrfguard.unprotected.GrouperStrutspopulateJoinGroups=%servletContext%/populateJoinGroups.do
org.owasp.csrfguard.unprotected.GrouperStrutspopulateListSavedGroups=%servletContext%/populateListSavedGroups.do
org.owasp.csrfguard.unprotected.GrouperStrutspopulateListSavedStems=%servletContext%/populateListSavedStems.do
org.owasp.csrfguard.unprotected.GrouperStrutspopulateListSavedSubjects=%servletContext%/populateListSavedSubjects.do
org.owasp.csrfguard.unprotected.GrouperStrutspopulateManageGroups=%servletContext%/populateManageGroups.do
org.owasp.csrfguard.unprotected.GrouperStrutspopulateMoveGroupToStem=%servletContext%/populateMoveGroupToStem.do
org.owasp.csrfguard.unprotected.GrouperStrutspopulateMoveGroup=%servletContext%/populateMoveGroup.do
org.owasp.csrfguard.unprotected.GrouperStrutspopulateMovesCopiesLinks=%servletContext%/populateMovesCopiesLinks.do
org.owasp.csrfguard.unprotected.GrouperStrutspopulateMoveOtherStemToStem=%servletContext%/populateMoveOtherStemToStem.do
org.owasp.csrfguard.unprotected.GrouperStrutspopulateMoveStem=%servletContext%/populateMoveStem.do
org.owasp.csrfguard.unprotected.GrouperStrutspopulateMyGroups=%servletContext%/populateMyGroups.do
org.owasp.csrfguard.unprotected.GrouperStrutspopulateStemMember=%servletContext%/populateStemMember.do
org.owasp.csrfguard.unprotected.GrouperStrutspopulateStemPriviligees=%servletContext%/populateStemPriviligees.do
org.owasp.csrfguard.unprotected.GrouperStrutspopulateSubjectSummary=%servletContext%/populateSubjectSummary.do
org.owasp.csrfguard.unprotected.GrouperStrutsuserAudit=%servletContext%/userAudit.do



org.owasp.csrfguard.unprotected.GrouperSimpleMembershipUpdateImportExportExportSubjectIdsCsv=%servletContext%/grouperUi/app/SimpleMembershipUpdateImportExport.exportSubjectIdsCsv/*
org.owasp.csrfguard.unprotected.GrouperSimpleMembershipUpdateImportExportExportAllCsv=%servletContext%/grouperUi/app/SimpleMembershipUpdateImportExport.exportAllCsv/*

org.owasp.csrfguard.unprotected.GrouperUiV2MainIndex=%servletContext%/grouperUi/app/UiV2Main.index
org.owasp.csrfguard.unprotected.GrouperUiV2MainFolderMenu=%servletContext%/grouperUi/app/UiV2Main.folderMenu
org.owasp.csrfguard.unprotected.GrouperUiV2GroupAddMemberFilter=%servletContext%/grouperUi/app/UiV2Group.addMemberFilter
org.owasp.csrfguard.unprotected.GrouperUiV2GroupImportGroupExportSubmit=%servletContext%/grouperUi/app/UiV2GroupImport.groupExportSubmit
org.owasp.csrfguard.unprotected.GrouperUiV2StemCopyParentFolderFilter=%servletContext%/grouperUi/app/UiV2Stem.stemCopyParentFolderFilter
org.owasp.csrfguard.unprotected.GrouperUiV2StemCreateGroupParentFolderFilter=%servletContext%/grouperUi/app/UiV2Stem.createGroupParentFolderFilter
org.owasp.csrfguard.unprotected.GrouperUiV2StemCreateStemParentFolderFilter=%servletContext%/grouperUi/app/UiV2Stem.createStemParentFolderFilter
org.owasp.csrfguard.unprotected.GrouperUiV2SubjectAddToGroupFilter=%servletContext%/grouperUi/app/UiV2Subject.addToGroupFilter
org.owasp.csrfguard.unprotected.GrouperUiV2GroupUpdateFilter=%servletContext%/grouperUi/app/UiV2Group.groupUpdateFilter
org.owasp.csrfguard.unprotected.GrouperUiV2GroupCompositeFilter=%servletContext%/grouperUi/app/UiV2Group.groupCompositeFactorFilter
org.owasp.csrfguard.unprotected.GrouperUiV2StemAddMemberFilter=%servletContext%/grouperUi/app/UiV2Stem.addMemberFilter
org.owasp.csrfguard.unprotected.GrouperUiV2ExternalEntitiesAddGroupFilter=%servletContext%/grouperUi/app/UiV2ExternalEntities.addGroupFilter
org.owasp.csrfguard.unprotected.GrouperUiV2SubjectAddToStemFilter=%servletContext%/grouperUi/app/UiV2Subject.addToStemFilter
org.owasp.csrfguard.unprotected.GrouperUiV2SubjectAddToAttributeDefFilter=%servletContext%/grouperUi/app/UiV2Subject.addToAttributeDefFilter


6. Create WEB-INF/tld/csrfguard.tld

<?xml version="1.0"?>
  <!--
    The OWASP CSRFGuard Project, BSD License Eric Sheridan (eric@infraredsecurity.com),
    Copyright (c) 2011 All rights reserved. Redistribution and use in source and binary
    forms, with or without modification, are permitted provided that the following
    conditions are met: 1. Redistributions of source code must retain the above copyright
    notice, this list of conditions and the following disclaimer. 2. Redistributions in
    binary form must reproduce the above copyright notice, this list of conditions and the
    following disclaimer in the documentation and/or other materials provided with the
    distribution. 3. Neither the name of OWASP nor the names of its contributors may be
    used to endorse or promote products derived from this software without specific prior
    written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
    CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
    TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
    DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY
    DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
    BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
    PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
    WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
    ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
    OF SUCH DAMAGE.
  -->
<taglib xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee/web-jsptaglibrary_2_0.xsd" version="2.0">
  <tlib-version>1.2</tlib-version>
  <jsp-version>2.0</jsp-version>
  <short-name>Owasp CsrfGuard Tag Library</short-name>
  <uri>http://www.owasp.org/index.php/Category:OWASP_CSRFGuard_Project/Owasp.CsrfGuard.tld
  </uri>
  <tag>
    <name>token</name>
    <tag-class>org.owasp.csrfguard.tag.TokenTag</tag-class>
    <body-content>empty</body-content>
    <attribute>
      <name>uri</name>
      <required>false</required>
      <rtexprvalue>true</rtexprvalue>
    </attribute>
  </tag>
  <tag>
    <name>token-name</name>
    <tag-class>org.owasp.csrfguard.tag.TokenNameTag</tag-class>
    <body-content>empty</body-content>
  </tag>
  <tag>
    <name>token-value</name>
    <tag-class>org.owasp.csrfguard.tag.TokenValueTag</tag-class>
    <body-content>empty</body-content>
    <attribute>
      <name>uri</name>
      <required>false</required>
      <rtexprvalue>true</rtexprvalue>
    </attribute>
  </tag>
  <tag>
    <name>a</name>
    <tag-class>org.owasp.csrfguard.tag.ATag</tag-class>
    <dynamic-attributes>true</dynamic-attributes>
  </tag>
  <tag>
    <name>form</name>
    <tag-class>org.owasp.csrfguard.tag.FormTag</tag-class>
    <dynamic-attributes>true</dynamic-attributes>
  </tag>
</taglib>

7. Edit grouperExternal/appHtml/grouper.html    Add this entry under all the existing js files

    <script src="../../grouperExternal/public/OwaspJavaScriptServlet"></script> 

8. Create grouperExternal/public/csrfError.html.  Note, would be nice to have this in externalized text...

 CSRF token is missing, <a href="../../">start over</a>

9. Edit grouperUi/appHtml/grouper.html    Add this entry under all the existing js files

    <script src="../../grouperExternal/public/OwaspJavaScriptServlet"></script> 

10. Edit WEB-INF/grouperUi/templates/common/commonTaglib.jsp, add this line

<%@ taglib uri="/WEB-INF/tld/csrfguard.tld" prefix="csrf" %>

11. Edit WEB-INF/grouperUi/templates/simpleMembershipUpdate/simpleMembershipUpdateImport.jsp, add this line below the form tag

   <input type="hidden" name="<csrf:token-name/>" value="<csrf:token-value uri="/grouper/grouperUi/app/SimpleMembershipUpdateImportExport.importCsv"/>"/>

12. Edit jsp/head.jsp, add this line below the other script tags

  <script src="grouperExternal/public/OwaspJavaScriptServlet"></script>

13. Edit WEB-INF/grouperUi2/assetsJsp/commonBottom.jsp, add this below the script tags

 <script src="../../grouperExternal/public/OwaspJavaScriptServlet"></script>

14. Edit WEB-INF/grouperUi2/groupImport/groupImport.jsp

FROM

            <form id="importGroupFormId" enctype="multipart/form-data" method="post" >

TO

             <form id="importGroupFormId" enctype="multipart/form-data" method="post" >
               <%-- note this wont work for token per page --%>
               <input type="hidden" name="<csrf:token-name/>" value="<csrf:token-value />"/>

Note, you can test that it works by setting up a static HTML page to remove a member from a group, or you can comment out the JS include in the the head.jsp or other files and try to use the UI, you will get an error

  • No labels