Issue AEM-6.1 Sling POST Servlet- Upload an image to AEM DAM | Community
Skip to main content
Level 9
November 13, 2015
Solved

Issue AEM-6.1 Sling POST Servlet- Upload an image to AEM DAM

  • November 13, 2015
  • 12 replies
  • 4719 views

Hey Guys,

I am trying to use the OOTB Post servlet in 6.1 referring to the below blog. It works fine in 5.6.1, but in 6.1, i believe there is a bug which does not let me POST successfully, i keep getting 403, forbidden error.  Can someone point out any necessary configuration missing here?

http://blogs.adobe.com/experiencedelivers/experience-management/how_to_upload_animageviaslingpostservlet/

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by kautuk_sahni

Hi 

As mentioned by Opkar Gill, if the error is CSRF, then configure the referrer filter.

Issues with Cross-Site Request Forgery

This is a security issue from the CRX Security Checklist, that is also appropriate to CQ.

To address known security issues with Cross-Site Request Forgery (CSRF) in CRX WebDAV and Apache Sling you need to configure the Referrer filter.

The referrer filter service is an OSGi service that allows you to configure:

  • which http methods should be filtered
  • whether an empty referrer header is allowed
  • and a white list of servers to be allowed in addition to the server host.

By default, all variations of localhost and the current host names the server is bound to are in the white list.

To configure the referrer filter service:

  • Open the Apache Felix console (Configurations) at:
       http://<server>:<port_number>/system/console/configMgr

  • Login as admin.

  • In the Configurations menu, select:

        Apache Sling Referrer Filter
     

  • In the Allow Hosts field, enter all hosts that are allowed as a referrer. Each entry needs to be of the form
       <protocol>://<server>:<port> 
    For example:

    • http://allowed.server:80 allows all requests from this server with the given port.
    • If you also want to allow https requests, you have to enter a second line.
    • If you allow all ports from that server you can use 0 as the port number.
       
  • Check the Allow Empty field, if you want to allow empty/missing referrer headers.

  • Edit the methods this filter should use for checks with the Filter Methods field.
     

  • Click Save to save your changes.

    Link: https://docs.adobe.com/docs/en/aem/6-1/administer/security/security-checklist.html#Protect against Cross-Site Request Forgery

     

    I hope this would help you.

    Thanks and Regards

    Kautuk Sahni

    12 replies

    Level 9
    November 13, 2015

    Anyone facing similar issue?

    smacdonald2008
    Level 10
    November 13, 2015

    See this blog that talks about uploading DAM assets using a custom sling servlet and Asset manager API

    http://scottsdigitalcommunity.blogspot.ca/2013/07/uploading-files-to-adobe-experience.html

    The benefit of a custom servlet is you have more control what happens when the image is posted to the server. 

    Adobe Employee
    November 13, 2015

    Hi,

    can you post the error? Is it a CSRF exception?

    "com.adobe.granite.csrf.impl.CSRFFilter isValidRequest: empty CSRF token - rejecting"

    Regards,

    Opkar

    Level 9
    November 16, 2015

    Opkar Gill wrote...

    Hi,

    can you post the error? Is it a CSRF exception?

    "com.adobe.granite.csrf.impl.CSRFFilter isValidRequest: empty CSRF token - rejecting"

    Regards,

    Opkar

     

    Yes i do see this, as an Info log level -  empty CSRF token - rejecting

    I have attached the error log in the txt file.

    On form submit, in the Firebug console, i see a 403 Forbidden, according to me, it looks like it just does not create the non existing path and thus does not upload an asset , which used to work just fine in 5.6.1

    I have also tried to add a path , /content/dam/ to the configuration, "Apache Sling Servlet/Script Resolver and Error Handler"  but in vain.

    Level 9
    November 16, 2015

    smacdonald2008 wrote...

    See this blog that talks about uploading DAM assets using a custom sling servlet and Asset manager API

    http://scottsdigitalcommunity.blogspot.ca/2013/07/uploading-files-to-adobe-experience.html

    The benefit of a custom servlet is you have more control what happens when the image is posted to the server. 

     

    Hey Scott,

    I totally agree. but this was the approach chosen over the servlet for the time-being, for a simple form post with conditions using apache sling POST. But since this was working in 5.6.1, unsure what configuration might be missing to make this actually work.

    kautuk_sahni
    Community Manager
    kautuk_sahniCommunity ManagerAccepted solution
    Community Manager
    November 16, 2015

    Hi 

    As mentioned by Opkar Gill, if the error is CSRF, then configure the referrer filter.

    Issues with Cross-Site Request Forgery

    This is a security issue from the CRX Security Checklist, that is also appropriate to CQ.

    To address known security issues with Cross-Site Request Forgery (CSRF) in CRX WebDAV and Apache Sling you need to configure the Referrer filter.

    The referrer filter service is an OSGi service that allows you to configure:

    • which http methods should be filtered
    • whether an empty referrer header is allowed
    • and a white list of servers to be allowed in addition to the server host.

    By default, all variations of localhost and the current host names the server is bound to are in the white list.

    To configure the referrer filter service:

    • Open the Apache Felix console (Configurations) at:
         http://<server>:<port_number>/system/console/configMgr

    • Login as admin.

    • In the Configurations menu, select:

          Apache Sling Referrer Filter
       

    • In the Allow Hosts field, enter all hosts that are allowed as a referrer. Each entry needs to be of the form
         <protocol>://<server>:<port> 
      For example:

      • http://allowed.server:80 allows all requests from this server with the given port.
      • If you also want to allow https requests, you have to enter a second line.
      • If you allow all ports from that server you can use 0 as the port number.
         
    • Check the Allow Empty field, if you want to allow empty/missing referrer headers.

    • Edit the methods this filter should use for checks with the Filter Methods field.
       

    • Click Save to save your changes.

      Link: https://docs.adobe.com/docs/en/aem/6-1/administer/security/security-checklist.html#Protect against Cross-Site Request Forgery

       

      I hope this would help you.

      Thanks and Regards

      Kautuk Sahni

      Kautuk Sahni
      Level 9
      November 16, 2015

      kautuksahni wrote...

      Hi 

      As mentioned by Opkar Gill, if the error is CSRF, then configure the referrer filter.

      Issues with Cross-Site Request Forgery

      This is a security issue from the CRX Security Checklist, that is also appropriate to CQ.

      To address known security issues with Cross-Site Request Forgery (CSRF) in CRX WebDAV and Apache Sling you need to configure the Referrer filter.

      The referrer filter service is an OSGi service that allows you to configure:

      • which http methods should be filtered
      • whether an empty referrer header is allowed
      • and a white list of servers to be allowed in addition to the server host.

      By default, all variations of localhost and the current host names the server is bound to are in the white list.

      To configure the referrer filter service:

      • Open the Apache Felix console (Configurations) at:
           http://<server>:<port_number>/system/console/configMgr

      • Login as admin.

      • In the Configurations menu, select:

            Apache Sling Referrer Filter
         

      • In the Allow Hosts field, enter all hosts that are allowed as a referrer. Each entry needs to be of the form
           <protocol>://<server>:<port> 
        For example:

        • http://allowed.server:80 allows all requests from this server with the given port.
        • If you also want to allow https requests, you have to enter a second line.
        • If you allow all ports from that server you can use 0 as the port number.
           
      • Check the Allow Empty field, if you want to allow empty/missing referrer headers.

      • Edit the methods this filter should use for checks with the Filter Methods field.
         

      • Click Save to save your changes.

        Link: https://docs.adobe.com/docs/en/aem/6-1/administer/security/security-checklist.html#Protect against Cross-Site Request Forgery

         

        I hope this would help you.

        Thanks and Regards

        Kautuk Sahni

         

         

         

        I gave it a shot, but looks like it did not help, can you please try it from your end as well? I still see the "com.adobe.granite.csrf.impl.CSRFFilter isValidRequest: empty CSRF token - rejecting" which is not an error , but an INFO log level.

        On the page , on submit, i see the error attached

        Here is the link to the blog

        http://blogs.adobe.com/experiencedelivers/experience-management/how_to_upload_animageviaslingpostservlet/

        Level 9
        November 16, 2015

        NitroHazeDev wrote...

        kautuksahni wrote...

        Hi 

        As mentioned by Opkar Gill, if the error is CSRF, then configure the referrer filter.

        Issues with Cross-Site Request Forgery

        This is a security issue from the CRX Security Checklist, that is also appropriate to CQ.

        To address known security issues with Cross-Site Request Forgery (CSRF) in CRX WebDAV and Apache Sling you need to configure the Referrer filter.

        The referrer filter service is an OSGi service that allows you to configure:

        • which http methods should be filtered
        • whether an empty referrer header is allowed
        • and a white list of servers to be allowed in addition to the server host.

        By default, all variations of localhost and the current host names the server is bound to are in the white list.

        To configure the referrer filter service:

        • Open the Apache Felix console (Configurations) at:
             http://<server>:<port_number>/system/console/configMgr

        • Login as admin.

        • In the Configurations menu, select:

              Apache Sling Referrer Filter
           

        • In the Allow Hosts field, enter all hosts that are allowed as a referrer. Each entry needs to be of the form
             <protocol>://<server>:<port> 
          For example:

          • http://allowed.server:80 allows all requests from this server with the given port.
          • If you also want to allow https requests, you have to enter a second line.
          • If you allow all ports from that server you can use 0 as the port number.
             
        • Check the Allow Empty field, if you want to allow empty/missing referrer headers.

        • Edit the methods this filter should use for checks with the Filter Methods field.
           

        • Click Save to save your changes.

          Link: https://docs.adobe.com/docs/en/aem/6-1/administer/security/security-checklist.html#Protect against Cross-Site Request Forgery

           

          I hope this would help you.

          Thanks and Regards

          Kautuk Sahni

           

           

           

          I gave it a shot, but looks like it did not help, can you please try it from your end as well? I still see the "com.adobe.granite.csrf.impl.CSRFFilter isValidRequest: empty CSRF token - rejecting" which is not an error , but an INFO log level.

          On the page , on submit, i see the error attached

          Here is the link to the blog

          http://blogs.adobe.com/experiencedelivers/experience-management/how_to_upload_animageviaslingpostservlet/

           

          Attaching the log

          Lokesh_Shivalingaiah
          Level 10
          November 16, 2015

          Hey, Did you try writing your own POST Servlet instead of using the SlingPostServlet ?

          Level 9
          November 19, 2015

          For anyone facing similar issues, please find the workaround, if you do not want to write a servlet but would like to use the OOTB post servlet

          Just  dump in the html into a component, an html component is what i have used. Do remember to upload multiple assets at a path, just like the aem dam, you could have the form action similar to "/content/dam.createasset.html"