Azure / Azure/azure-functions-python-worker

[Bug] Python Azure Function worker incorrectly URL encodes cookie value

Đang mở
#1,794 1 bình luận 2 reaction 0 người được giao Xem trên GitHub
area:python-functions bug python python-sdk
Ngôn ngữ chính
Python
Star
357
Fork
116
Merge trung bình
32 phút
Pull request đã merge (30 ngày)
1

Mô tả

### Expected Behavior

Azure Function worker using Python FastAPI should not URL encode cookie values

Expected behavior on HTTP Response Headers:
`set-cookie: test="hello//world"; Path=/; SameSite=lax`

e.g. when using Python FastAPI without Azure Functions, it correctly does not URL encode.
````
import uvicorn
from fastapi import FastAPI
from fastapi.responses import PlainTextResponse

app = FastAPI()

@app.get("/")
def http_trigger():
response = PlainTextResponse("", status_code=200)
response.set_cookie(key='test', value='hello//world')

return response

if __name__ == "__main__":
uvicorn.run(app, host="127.0.0.1", port=7071)

````

Run `curl -v http://localhost:7071/` and response is correct as `set-cookie: test="hello//world"; Path=/; SameSite=lax`

### Actual Behavior

Actual incorrect behavior on HTTP Response Headers, cookie value is incorrect and unexpectedly URL encoded

`Set-Cookie: test=hello%2F%2Fworld; domain=; path=/; samesite=lax`

Tested bug with
* Python 3.12 with FastAPI
* Azure Functions Core tools 4.3.0 locally
* Deployed to production Azure Function

### Steps to Reproduce

1. Run `func start` or deploy to Azure using sample code provided below
2. Send a test HTTP request e.g. `curl -v http://localhost:7071/`
3. Azure Functions worker incorrectly URL encodes the response cookie value in the `Set-Cookie` header

### Relevant code being tried

```shell
import azure.functions as func
from fastapi import FastAPI
from fastapi.responses import PlainTextResponse

app = FastAPI()
func_app = func.AsgiFunctionApp(app=app, http_auth_level=func.AuthLevel.ANONYMOUS)

@app.get("/")
def http_trigger():

response = PlainTextResponse("", status_code=200)
response.set_cookie(key='test', value='hello//world')

return response
```

### Relevant log output

```shell
N/A
```

### requirements.txt file

```shell
azure-functions
fastapi
```

### Where are you facing this problem?

Production Environment (explain below)

### Function app name

Private

### Additional Information

_No response_

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Hướng nghiên cứu

Bắt đầu với đường dẫn adapter ASGI được tạo bởi func.AsgiFunctionApp và so sánh cách xử lý response header của nó với output của PlainTextResponse.set_cookie trong FastAPI. Tái hiện bằng func start và curl -v với giá trị hello//world; hoàn tất khi header Set-Cookie giữ nguyên giá trị cookie mong đợi và một kiểm tra hồi quy bao quát trường hợp này.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Đánh giá

Công nghệ
azure, fastapi, python
Lĩnh vực
api, backend
Loại issue
Lỗi
Độ khó
3/5
Thời gian dự kiến
1-2 ngày
Mức độ hoạt động
Đình trệ
Độ rõ ràng
Đặc tả rõ ràng
Mức phù hợp với người mới
45/100

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.