美文网首页
【踩坑记录】ZUUL网关响应头部不返回

【踩坑记录】ZUUL网关响应头部不返回

作者: ZT5250Z | 来源:发表于2020-10-19 10:53 被阅读0次

    前言

    最近在做项目,使用zuul作为统一的网关,对接了一个比较特殊的接口,需要返回所有的response header供后续使用

    问题

    由于接口是有依赖关系的,会依赖于第一次请求返回的response header中的一个Authorization信息,后面的请求都会把这个放在request header中带过来,但是在实际调试中发现,后续的请求一直都没有这个header信息,因为除了Authrization之外还有很多其他自定义的response header,在调试中都看到了,也都正常返回给调用方了,一开始没有想到会有response header丢失的问题,所以把问题定位在了客户端,最后客户端通过抓包工具确定了,确实是网关没有返回

    问题确定了,那搜索方向就缩小了,由于代码里全局都没有搜索到Authorization,所以断定是ZUUL网关搞的鬼,通过一番网上冲浪,原来ZUUL有个默认过滤敏感信息的逻辑,并且是可配置的

    找到zuul的源码并证实了这一点,以下为zuul源码中的内容:


    zuulheader.png

    关键代码:

    /**
         * List of sensitive headers that are not passed to downstream requests. Defaults to a
         * "safe" set of headers that commonly contain user credentials. It's OK to remove
         * those from the list if the downstream service is part of the same system as the
         * proxy, so they are sharing authentication data. If using a physical URL outside
         * your own domain, then generally it would be a bad idea to leak user credentials.
         */
        private Set<String> sensitiveHeaders = new LinkedHashSet<>(
                Arrays.asList("Cookie", "Set-Cookie", "Authorization"));
    

    由此可见,默认的"Cookie",, "Set-Cookie","Authorization"会当做敏感信息头部不返回出去

    解决

    问题定位了,那就好解决了,可以通过修改配置来调整屏蔽的敏感信息头部,甚至可以不屏蔽敏感信息头部,全都返回,因为默认是有三个敏感信息头部的,所以需要手动设置来改变这个默认配置

    需要在yml或者properties文件中增加下列配置
    yml

    zuul:
        sensitive-headers:
    

    properties

    zuul.sensitive-headers=
    

    可以自己指定要屏蔽的response header,如果不想屏蔽,都要返回,那直接不写具体的内容即可,但是必须要增加这个配置

    相关文章

      网友评论

          本文标题:【踩坑记录】ZUUL网关响应头部不返回

          本文链接:https://www.haomeiwen.com/subject/ftlkmktx.html