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

Forwarded request paths have escaped characters unescaped #864

Closed
worldspawn opened this issue Dec 22, 2023 · 3 comments
Closed

Forwarded request paths have escaped characters unescaped #864

worldspawn opened this issue Dec 22, 2023 · 3 comments
Labels
bug Something isn't working

Comments

@worldspawn
Copy link
Contributor

worldspawn commented Dec 22, 2023

Report

The request path api/Spaces-1/projects/Projects-45/refs%2fheads%2fdevelop/deploymentprocesses fails with 404 with keda http add-on in between. I believe this is because the escaped characters are unescaped in the forwarded request.

I get the same behaviour when i enable path rewriting in ingress.

Expected Behavior

Path not altered. Don't get a 404.

Actual Behavior

Path is altered, resulting in a 404.

Steps to Reproduce the Problem

  1. Make a request with an escaped forward slash %2f and observe it forwarded as /

Logs from KEDA HTTP operator

{"level":"info","ts":1703256074.7780826,"logger":"LoggingMiddleware","caller":"middleware/logging.go:73","msg":"10.50.10.146:39356 - - [22/Dec/2023:14:41:14 +0000] \"GET /api/Spaces-1/projects/Projects-45/refs/heads/develop/deploymentprocesses HTTP/1.1\" 404 69 \"\" \"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36\""}

HTTP Add-on Version

0.6.0

Kubernetes Version

1.28

Platform

Microsoft Azure

Anything else?

No response

@worldspawn worldspawn added the bug Something isn't working label Dec 22, 2023
@worldspawn worldspawn changed the title Forwarded request paths appear to have escaped charcaters unescaped Forwarded request paths appear to have escaped characters unescaped Dec 22, 2023
@worldspawn worldspawn changed the title Forwarded request paths appear to have escaped characters unescaped Forwarded request paths have escaped characters unescaped Dec 22, 2023
@tomkerkhove
Copy link
Member

Are you willing to contribute a fix?

@worldspawn
Copy link
Contributor Author

worldspawn commented Jan 4, 2024

I'm completely out of my element here... like I had to lookup how to create a new instance of something go (iow, starting from zero).

From what I can gather, setting RawPath on the new request to the value of RawPath of the forwarded request might fix this. Based on:

package main

import (
	"fmt"
	"log"
	"net/url"
)

func main() {
	u, err := url.Parse("http://example.com/api/Spaces-1/projects/Projects-45/refs%2fheads%2fdevelop/deploymentprocesses")
	if err != nil {
		log.Fatal(err)
	}

	p, err := url.Parse("http://example.com/")

	fmt.Println("Path:", u.Path)
	fmt.Println("RawPath:", u.RawPath)
	fmt.Println("EscapedPath:", u.EscapedPath())

	p.Path = u.Path
	fmt.Println("EscapedPath:", p.EscapedPath())
	p.RawPath = u.RawPath
	fmt.Println("EscapedPath:", p.EscapedPath())

}

@worldspawn
Copy link
Contributor Author

Fixed in PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Status: Done
Development

No branches or pull requests

2 participants