[ 
https://issues.apache.org/jira/browse/SLING-13355?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18141054#comment-18141054
 ] 

Joerg Hoh edited comment on SLING-13355 at 11/9/26, 1:57 PM:
-------------------------------------------------------------

I pulled an example from the logs, where the errorhandler is listed as a source 
for changing the content-type header.

There are a series of problems in this case:
* This is a request for a non-existing resource (a image), and for that 
content-type for the response should not be text/html in the first place. 
Meaning that the default error handler (which produces HTML in this case) 
should not be called.
* The fact, that the content-type is then changed after the error handler is 
invoked means, that somehow the extension "png" from the initial request seems 
to be carried over into the error handling, even though the error handling is 
supposed to create HTML.

{noformat}
GET /content/foo/apple-touch-icon-precomposed.png HTTP/1.1] 
org.apache.sling.engine.impl.SlingHttpServletResponseImpl Servlet 
BundledScriptServlet (/libs/cq/Page/Page.png.jsp) tried to override the 
'Content-Type' header from 'text/html;charset=utf-8' to 'image/png'. This is a 
violation of the RequestDispatcher.include() contract - 
https://jakarta.ee/specifications/servlet/4.0/apidocs/javax/servlet/requestdispatcher#include-javax.servlet.ServletRequest-javax.servlet.ServletResponse-.
 , Include stack: BundledScriptServlet (/libs/cq/Page/Page.png.jsp)#1. All 
RequestProgressTracker messages:       
      0 TIMER_START{Request Processing}
      1 COMMENT timer_end format is {<elapsed microseconds>,<timer name>} 
<optional message>
      6 LOG Method=GET, PathInfo=null
      8 TIMER_START{handleSecurity}
   1771 TIMER_END{1761,handleSecurity} authenticator 
org.apache.sling.auth.core.impl.SlingAuthenticator@5bcdc2e0 returns true
   3063 TIMER_START{ResourceResolution}
   3984 TIMER_END{910,ResourceResolution} 
URI=/content/foo/apple-touch-icon-precomposed.png resolves to 
Resource=NonExistingResource, path=/content/foo/apple-touch-icon-precomposed.png
   3989 LOG Resource Path Info: SlingRequestPathInfo: 
path='/content/foo/apple-touch-icon-precomposed.png', selectorString='null', 
extension='png', suffix='null'
   3990 TIMER_START{ServletResolution}
   3992 
TIMER_START{resolveServlet(/content/foo/apple-touch-icon-precomposed.png)}
   5019 LOG {0}: no servlet found
   5025 
TIMER_END{1032,resolveServlet(/content/foo/apple-touch-icon-precomposed.png)} 
Using servlet org.apache.sling.servlets.get.DefaultGetServlet
   5028 TIMER_END{1038,ServletResolution} 
URI=/content/foo/apple-touch-icon-precomposed.png handled by 
Servlet=org.apache.sling.servlets.get.DefaultGetServlet
   5029 LOG Applying REQUESTfilters
   5036 LOG Calling filter: 
com.adobe.granite.resourceresolverhelper.impl.ResourceResolverHelperImpl
   [ommitted irrelevant lines]
   6570 LOG Filter timing: 
filter=com.adobe.aem.developer.console.support.impl.apifirst.logging.HttpSlingFilter,
 inner=1106, total=1110, outer=4
   6577 LOG Applying Error filters
   6587 LOG Calling filter: org.apache.sling.i18n.impl.I18NFilter
   6590 LOG Calling filter: org.apache.sling.rewriter.impl.RewriterFilter
   6594 LOG Calling filter: com.adobe.granite.cors.impl.CORSFilter
   6603 TIMER_START{handleError:status=404}
   6618 TIMER_END{14,handleError:status=404} Using handler BundledScriptServlet 
(/apps/sling/servlet/errorhandler/404.html)
   6760 LOG Adding bindings took 84 microseconds
   9796 LOG Found processor for config ProcessorConfiguration: 
{contentTypes=[text/html], processErrorResponse=true, order=-1, active=true, 
valid=true, pipeline=(generator=Config(type=htmlparser, config={}), 
transformers=(Config(type=linkchecker, config={}), Config(type=mobile, 
config={component-optional=true}), Config(type=mobiledebug, 
config={component-optional=true}), Config(type=contentsync, 
config={component-optional=true}), serializer=Config(type=htmlwriter, 
config={}))} : Pipeline Processor 
(org.apache.sling.rewriter.impl.PipelineImpl@4ac872f5) : generator: Adobe AEM 
HTML Parser Generator, transformers: [Adobe AEM WebVitals Rewriter, Adobe AEM 
MetaTag PageId Injection Transformer, Adobe AEM MetaTag PageId Injection 
Transformer, Adobe AEM HTML Parser Transformer, 
com.day.cq.mcm.core.newsletter.NewsletterTransformerFactory$NewsletterTransformer@156912d4,
 com.day.cq.rewriter.linkchecker.impl.LinkCheckerTransformer@2fe2ecff, 
com.day.cq.wcm.mobile.core.impl.rewriter.MobileTransformer@411fd2f, 
com.day.cq.wcm.mobile.core.impl.device.DeviceInfoTransformerFactory$NullTransformer@dc77882,
 com.day.cq.wcm.contentsync.impl.rewriter.PathRewriterTransformer@50e5245c], 
serializer: com.day.cq.rewriter.processor.impl.SAXWriterFactory$1@6858bfab
  10101 LOG Including resource JcrNodeResource, type=cq:Page, superType=null, 
path=/content/foo/gb/en/404 (SlingRequestPathInfo: 
path='/content/foo/gb/en/404', selectorString='null', extension='png', 
suffix='null')
  10104 TIMER_START{resolveServlet(/content/foo/gb/en/404)}
  10117 TIMER_END{12,resolveServlet(/content/foo/gb/en/404)} Using servlet 
BundledScriptServlet (/libs/cq/Page/Page.png.jsp)
  10120 LOG Applying Includefilters
  10122 LOG Calling filter: com.adobe.granite.csrf.impl.CSRFFilter
  10128 LOG Calling filter: 
com.day.cq.personalization.impl.TargetComponentFilter
  10130 LOG Calling filter: com.day.cq.wcm.core.impl.page.PageLockFilter
  10134 LOG Calling filter: com.day.cq.wcm.core.impl.WCMComponentFilter
  10177 LOG Calling filter: 
com.adobe.granite.metrics.knownerrors.impl.ErrorLoggingComponentFilter
  10179 LOG Calling filter: com.adobe.cq.dam.cfm.ui.impl.EditorCacheFilter
  10183 LOG Calling filter: com.adobe.granite.uriprovider.dba.DBAHeaderFilter
  10198 LOG Calling filter: 
com.adobe.acs.commons.granite.ui.components.impl.include.IncludeDecoratorFilterImpl
  10352 LOG Calling filter: com.day.cq.wcm.core.impl.WCMDebugFilter
  10382 TIMER_START{BundledScriptServlet (/libs/cq/Page/Page.png.jsp)#1}
  10449 LOG Adding bindings took 33 microseconds_
{noformat}


was (Author: joerghoh):

I pulled an example from the logs, where the errorhandler is listed as a source 
for changing the content-type header.

{noformat}
GET /content/foo/apple-touch-icon-precomposed.png HTTP/1.1] 
org.apache.sling.engine.impl.SlingHttpServletResponseImpl Servlet 
BundledScriptServlet (/libs/cq/Page/Page.png.jsp) tried to override the 
'Content-Type' header from 'text/html;charset=utf-8' to 'image/png'. This is a 
violation of the RequestDispatcher.include() contract - 
https://jakarta.ee/specifications/servlet/4.0/apidocs/javax/servlet/requestdispatcher#include-javax.servlet.ServletRequest-javax.servlet.ServletResponse-.
 , Include stack: BundledScriptServlet (/libs/cq/Page/Page.png.jsp)#1. All 
RequestProgressTracker messages:       
      0 TIMER_START{Request Processing}
      1 COMMENT timer_end format is {<elapsed microseconds>,<timer name>} 
<optional message>
      6 LOG Method=GET, PathInfo=null
      8 TIMER_START{handleSecurity}
   1771 TIMER_END{1761,handleSecurity} authenticator 
org.apache.sling.auth.core.impl.SlingAuthenticator@5bcdc2e0 returns true
   3063 TIMER_START{ResourceResolution}
   3984 TIMER_END{910,ResourceResolution} 
URI=/content/foo/apple-touch-icon-precomposed.png resolves to 
Resource=NonExistingResource, path=/content/foo/apple-touch-icon-precomposed.png
   3989 LOG Resource Path Info: SlingRequestPathInfo: 
path='/content/foo/apple-touch-icon-precomposed.png', selectorString='null', 
extension='png', suffix='null'
   3990 TIMER_START{ServletResolution}
   3992 
TIMER_START{resolveServlet(/content/foo/apple-touch-icon-precomposed.png)}
   5019 LOG {0}: no servlet found
   5025 
TIMER_END{1032,resolveServlet(/content/foo/apple-touch-icon-precomposed.png)} 
Using servlet org.apache.sling.servlets.get.DefaultGetServlet
   5028 TIMER_END{1038,ServletResolution} 
URI=/content/foo/apple-touch-icon-precomposed.png handled by 
Servlet=org.apache.sling.servlets.get.DefaultGetServlet
   5029 LOG Applying REQUESTfilters
   5036 LOG Calling filter: 
com.adobe.granite.resourceresolverhelper.impl.ResourceResolverHelperImpl
   [ommitted irrelevant lines]
   6570 LOG Filter timing: 
filter=com.adobe.aem.developer.console.support.impl.apifirst.logging.HttpSlingFilter,
 inner=1106, total=1110, outer=4
   6577 LOG Applying Error filters
   6587 LOG Calling filter: org.apache.sling.i18n.impl.I18NFilter
   6590 LOG Calling filter: org.apache.sling.rewriter.impl.RewriterFilter
   6594 LOG Calling filter: com.adobe.granite.cors.impl.CORSFilter
   6603 TIMER_START{handleError:status=404}
   6618 TIMER_END{14,handleError:status=404} Using handler BundledScriptServlet 
(/apps/sling/servlet/errorhandler/404.html)
   6760 LOG Adding bindings took 84 microseconds
   9796 LOG Found processor for config ProcessorConfiguration: 
{contentTypes=[text/html], processErrorResponse=true, order=-1, active=true, 
valid=true, pipeline=(generator=Config(type=htmlparser, config={}), 
transformers=(Config(type=linkchecker, config={}), Config(type=mobile, 
config={component-optional=true}), Config(type=mobiledebug, 
config={component-optional=true}), Config(type=contentsync, 
config={component-optional=true}), serializer=Config(type=htmlwriter, 
config={}))} : Pipeline Processor 
(org.apache.sling.rewriter.impl.PipelineImpl@4ac872f5) : generator: Adobe AEM 
HTML Parser Generator, transformers: [Adobe AEM WebVitals Rewriter, Adobe AEM 
MetaTag PageId Injection Transformer, Adobe AEM MetaTag PageId Injection 
Transformer, Adobe AEM HTML Parser Transformer, 
com.day.cq.mcm.core.newsletter.NewsletterTransformerFactory$NewsletterTransformer@156912d4,
 com.day.cq.rewriter.linkchecker.impl.LinkCheckerTransformer@2fe2ecff, 
com.day.cq.wcm.mobile.core.impl.rewriter.MobileTransformer@411fd2f, 
com.day.cq.wcm.mobile.core.impl.device.DeviceInfoTransformerFactory$NullTransformer@dc77882,
 com.day.cq.wcm.contentsync.impl.rewriter.PathRewriterTransformer@50e5245c], 
serializer: com.day.cq.rewriter.processor.impl.SAXWriterFactory$1@6858bfab
  10101 LOG Including resource JcrNodeResource, type=cq:Page, superType=null, 
path=/content/foo/gb/en/404 (SlingRequestPathInfo: 
path='/content/foo/gb/en/404', selectorString='null', extension='png', 
suffix='null')
  10104 TIMER_START{resolveServlet(/content/foo/gb/en/404)}
  10117 TIMER_END{12,resolveServlet(/content/foo/gb/en/404)} Using servlet 
BundledScriptServlet (/libs/cq/Page/Page.png.jsp)
  10120 LOG Applying Includefilters
  10122 LOG Calling filter: com.adobe.granite.csrf.impl.CSRFFilter
  10128 LOG Calling filter: 
com.day.cq.personalization.impl.TargetComponentFilter
  10130 LOG Calling filter: com.day.cq.wcm.core.impl.page.PageLockFilter
  10134 LOG Calling filter: com.day.cq.wcm.core.impl.WCMComponentFilter
  10177 LOG Calling filter: 
com.adobe.granite.metrics.knownerrors.impl.ErrorLoggingComponentFilter
  10179 LOG Calling filter: com.adobe.cq.dam.cfm.ui.impl.EditorCacheFilter
  10183 LOG Calling filter: com.adobe.granite.uriprovider.dba.DBAHeaderFilter
  10198 LOG Calling filter: 
com.adobe.acs.commons.granite.ui.components.impl.include.IncludeDecoratorFilterImpl
  10352 LOG Calling filter: com.day.cq.wcm.core.impl.WCMDebugFilter
  10382 TIMER_START{BundledScriptServlet (/libs/cq/Page/Page.png.jsp)#1}
  10449 LOG Adding bindings took 33 microseconds_
{noformat}

> Make request error handlign aware of content-types
> --------------------------------------------------
>
>                 Key: SLING-13355
>                 URL: https://issues.apache.org/jira/browse/SLING-13355
>             Project: Sling
>          Issue Type: New Feature
>          Components: Engine
>            Reporter: Joerg Hoh
>            Priority: Major
>
> Currently the error handling in the Sling Engine is not aware of the 
> content-type which has been already set.
> For example I have this warn message:
> {quote}
> POST /content/dam/folder.initiateUpload.json HTTP/1.1] 
> org.apache.sling.engine.impl.SlingHttpServletResponseImpl Servlet 
> BundledScriptServlet (/libs/sling/servlet/errorhandler/404.jsp) tried to 
> override the 'Content-Type' header from 'application/json' to 'text/html'. 
> This is a violation of the RequestDispatcher.include() contract - 
> https://jakarta.ee/specifications/servlet/4.0/apidocs/javax/servlet/requestdispatcher#include-javax.servlet.ServletRequest-javax.servlet.ServletResponse-.
>  , Include stack: BundledScriptServlet 
> (/libs/sling/servlet/errorhandler/404.jsp)#1 -> 
> com.adobe.cq.assetcompute.impl.servlet.InitiateUploadAssetServlet#0. All 
> RequestProgressTracker messages: 
> [...]
> 310546 TIMER_END\{771,ServletResolution\} 
> URI=/content/dam/folder.initiateUpload.json handled by 
> Servlet=com.adobe.cq.assetcompute.impl.servlet.InitiateUploadAssetServlet
> [...]
> 311308 
> TIMER_START\{com.adobe.cq.assetcompute.impl.servlet.InitiateUploadAssetServlet#0\}
>  311659 LOG Applying Error filters
> [...]
>  311834 TIMER_START\{handleError:status=404\}
>  312328 TIMER_END\{494,handleError:status=404\} Using handler 
> BundledScriptServlet (/apps/sling/servlet/errorhandler/404.html)
>  312938 
> TIMER_START\{resolveIncludedResource(/libs/sling/servlet/errorhandler/404.jsp)\}
>  313050 
> TIMER_END\{112,resolveIncludedResource(/libs/sling/servlet/errorhandler/404.jsp)\}
>  path=/libs/sling/servlet/errorhandler/404.jsp resolves to 
> Resource=ServletResource, servlet=BundledScriptServlet 
> (/libs/sling/servlet/errorhandler/404.jsp), 
> path=/libs/sling/servlet/errorhandler/404.jsp
>  313062 LOG Including resource ServletResource, servlet=BundledScriptServlet 
> (/libs/sling/servlet/errorhandler/404.jsp), 
> path=/libs/sling/servlet/errorhandler/404.jsp (SlingRequestPathInfo: 
> path='/libs/sling/servlet/errorhandler/404.jsp', 
> selectorString='initiateUpload', extension='json', suffix='null')
>  313065 
> TIMER_START\{resolveServlet(/libs/sling/servlet/errorhandler/404.jsp)\}
>  313094 
> TIMER_END\{28,resolveServlet(/libs/sling/servlet/errorhandler/404.jsp)\} 
> Using servlet BundledScriptServlet (/libs/sling/servlet/errorhandler/404.jsp)
>  313345 TIMER_START\{BundledScriptServlet 
> (/libs/sling/servlet/errorhandler/404.jsp)#1\}
> {quote}
> Here the com.adobe.cq.assetcompute.impl.servlet.InitiateUploadAssetServlet 
> triggers the error handling of the Sling Engine (for whatever reason, but at 
> this point it already has set the content-type to "application/json". And as 
> a next step the error handler kicks in and writes the error messages with the 
> content-type text/html.
> We should fix this for 2 reasons:
> # It is a potential XSS (the browser's JSON parser encounters HTML markup)
> # In my experience the default error handling frequently focuses on the the 
> "main request" only, that means it renders HTML; in some cases this error 
> handling is even configured to render full fledged HTML pages which can get 
> slow. This can be misused for DOS attacks, e.g. by requesting non-existing 
> images.
> We should make the error handling aware of the requested content-type and be 
> able to register error handlers by status and content-type.



--
This message was sent by Atlassian Jira
(v10.3.26#10030026)

Reply via email to