Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

KNOX-2946 - Cookie Path Scoping doesn't work when using default topology URL #786

Merged
merged 2 commits into from
Sep 5, 2023

Conversation

zeroflag
Copy link
Contributor

@zeroflag zeroflag commented Aug 15, 2023

What changes were proposed in this pull request?

When cookie path scoping is enabled knox will update the Path attribute of the cookies with /gateway/topology_name.
This doesn't work when a service is accessed via the default topology name (there is no gateway/topology_name in the url).

How was this patch tested?

Enable cookie scoping + set default topology to sandbox:

    <property>
        <name>default.app.topology.name</name>
        <value>sandbox</value>
    </property>
    <property>
        <name>gateway.scope.cookies.feature.enabled</name>
        <value>true</value>
    </property>

Set service url in sandbox.xml:

    <service>
        <role>HIVE</role>
        <url>http://localhost:1701</url>
    </service>

Set up a test http server:

Teapot on
    GET: '/' -> [:req |  
        ZnResponse noContent
    	      addCookie: ((ZnCookie name: 'test' value:'val') path: '/original/path'); 
    	      yourself 
         ];
	start. 

Unblock cookies in service.xml (data/services/hive/0.13.0/service.xml):

       <param>
            <name>responseExcludeHeaders</name>
            <value>SET-COOKIE;asdfg</value>
      </param>

Cookie path is updated when using the full URL:

$ curl -u admin:admin-password -k -v https://localhost:8443/gateway/sandbox/hive

< HTTP/1.1 204 No Content
< Set-Cookie: test=val; Path=/gateway/sandbox/original/path

Cookie path is not updated when using the default URL:

$ curl -u admin:admin-password -k -v https://localhost:8443/hive

< HTTP/1.1 204 No Content
< Set-Cookie: test=val; path=/original/path

Copy link
Contributor

@pzampino pzampino left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Couple of questions...

@@ -43,7 +45,12 @@ public void init( FilterConfig filterConfig ) throws ServletException {
@Override
protected void doFilter( HttpServletRequest request, HttpServletResponse response, FilterChain chain )
throws IOException, ServletException {
chain.doFilter(request, new CookieScopeResponseWrapper(response, gatewayPath, topologyName));
if ("true".equals(request.getAttribute(DEFAULT_TOPOLOGY_FORWARD_ATTRIBUTE_NAME))) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would Boolean.parseBoolean(request.getAttribute(DEFAULT_TOPOLOGY_FORWARD_ATTRIBUTE_NAME)) be better here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That might be a bit better. I'll modify it.

Copy link
Contributor

@pzampino pzampino left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@zeroflag zeroflag merged commit dcbba88 into apache:master Sep 5, 2023
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants