Changes between Version 1 and Version 2 of proposals/CSRFTokens


Ignore:
Timestamp:
Feb 24, 2013, 11:45:19 AM (11 years ago)
Author:
josegar74
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • proposals/CSRFTokens

    v1 v2  
    4444'''1)''' A new base service class for services that require CSRF (Cross Site Request Forgery) tokens: {{{BaseSecureService}}}
    4545
    46 This class validates the CSRF token:
     46This class validates the CSRF token before processing the service:
    4747
    4848 * If it's not valid and exception {{{ServiceNotAllowedEx}}} is thrown.
    4949 * If it's valid, the service processing continues.
    5050
     51{{{
     52package jeeves.services;
     53
     54public 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
    5168Services that require CSRF tokens must extend this class and implement the logic in {{{doExec}}} method instead of {{{exec}}} method.
    5269
     70
     71{{{
     72package org.fao.geonet.services.user;
     73
     74public class Update extends BaseSecureService
     75{
     76        public Element doExec(Element params, ServiceContext context) throws Exception
     77        {
     78                // Service logic 
     79        }
     80}
     81}}}
     82
    5383Code: https://github.com/josegar74/core-geonetwork/blob/csrf/jeeves/src/main/java/jeeves/services/BaseSecureService.java
     84
    5485Example service requiring CSRF token: https://github.com/josegar74/core-geonetwork/blob/csrf/web/src/main/java/org/fao/geonet/services/user/Update.java
    5586
    5687'''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.
    5788
    58 CSRF tokens are created using SecureRandom java class
     89CSRF tokens are created using {{{SecureRandom}}} java class.
    5990
    6091Code: 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
     
    97128=== Backwards Compatibility Issues ===
    98129
    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.
     130User 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.
    100131
    101 These changes don't affect interfaces like CSW.
     132UI WIdgets requires to be changed to use the CSRF token.
    102133
    103134=== New libraries added ===