Changes between Version 1 and Version 2 of proposals/CSRFTokens
- Timestamp:
- 02/24/13 11:45:19 (12 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
proposals/CSRFTokens
v1 v2 44 44 '''1)''' A new base service class for services that require CSRF (Cross Site Request Forgery) tokens: {{{BaseSecureService}}} 45 45 46 This class validates the CSRF token :46 This class validates the CSRF token before processing the service: 47 47 48 48 * If it's not valid and exception {{{ServiceNotAllowedEx}}} is thrown. 49 49 * If it's valid, the service processing continues. 50 50 51 {{{ 52 package jeeves.services; 53 54 public abstract class BaseSecureService implements Service { 55 public final Element exec(Element params, ServiceContext context) throws Exception { 56 if (!CSRFUtil.isValidToken(params, context)) { 57 throw new ServiceNotAllowedEx("Service not allowed. CSRF Token is not valid"); 58 } 59 60 return doExec(params, context); 61 } 62 63 /** Services that require CSRF tokens must implement doExec instead of exec **/ 64 protected abstract Element doExec(Element params, ServiceContext context) throws Exception; 65 } 66 }}} 67 51 68 Services that require CSRF tokens must extend this class and implement the logic in {{{doExec}}} method instead of {{{exec}}} method. 52 69 70 71 {{{ 72 package org.fao.geonet.services.user; 73 74 public class Update extends BaseSecureService 75 { 76 public Element doExec(Element params, ServiceContext context) throws Exception 77 { 78 // Service logic 79 } 80 } 81 }}} 82 53 83 Code: https://github.com/josegar74/core-geonetwork/blob/csrf/jeeves/src/main/java/jeeves/services/BaseSecureService.java 84 54 85 Example service requiring CSRF token: https://github.com/josegar74/core-geonetwork/blob/csrf/web/src/main/java/org/fao/geonet/services/user/Update.java 55 86 56 87 '''2)''' A new service to create/retrieve a CSRF token: {{{secure.token}}}. This service is used to provide the secure token in services that create forms (see next point) and can be used from scripts that use actual !GeoNetwork services that have been changed to require CSRF tokens. For example, a script that call {{{metadata.category}}} to update the categories of metadata, will require to call first {{{secure.token}}} to get the token and use it in {{{metadata.category}}} calls. 57 88 58 CSRF tokens are created using SecureRandom java class89 CSRF tokens are created using {{{SecureRandom}}} java class. 59 90 60 91 Code: https://github.com/josegar74/core-geonetwork/blob/csrf/jeeves/src/main/java/jeeves/services/GetSecureToken.java, https://github.com/josegar74/core-geonetwork/blob/csrf/jeeves/src/main/java/jeeves/utils/CSRFUtil.java … … 97 128 === Backwards Compatibility Issues === 98 129 99 User scripts using !GeoNetwork services to update data will require to be updated to use {{{secure.token}}} to retrieve the CSRF token and use it in the services. See Proposal description (point 2) for more details. 130 User scripts using !GeoNetwork services to update data will require to be updated to use {{{secure.token}}} to retrieve the CSRF token and use it in the services. See Proposal description (point 2) for more details. These changes don't affect interfaces like CSW. 100 131 101 These changes don't affect interfaces like CSW.132 UI WIdgets requires to be changed to use the CSRF token. 102 133 103 134 === New libraries added ===