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

[vweb] Error parsing url with // appended #20476

Closed
billpcs opened this issue Jan 10, 2024 · 1 comment · Fixed by #20504
Closed

[vweb] Error parsing url with // appended #20476

billpcs opened this issue Jan 10, 2024 · 1 comment · Fixed by #20504
Labels
Bug This tag is applied to issues which reports bugs.

Comments

@billpcs
Copy link
Contributor

billpcs commented Jan 10, 2024

Describe the bug

If a user tries to load a vweb webpage and the url ends with //, then the page fails to load.

This can have various consequences. For example gitly shows a Cloudflare error currently.

My cloud-deployed server goes to 100% CPU.

Locally, I just get an error on the browser.

image

Reproduction Steps

Create simple web server project

$ v new --web test

Run the server

$ v run .

Visit the problematic path

Load http://localhost:8082// on a web browser

Expected Behavior

The webpage loads. It either redirects to home, displays a 404 error or something normal.

Current Behavior

The webpage shows The connection was reset on Firefox and This page isn’t working on Chrome

The log shows

[vweb] tid: 005, error parsing path: net.urllib.parse: failed parsing url
[vweb] tid: 000, error parsing path: net.urllib.parse: failed parsing url
[vweb] tid: 006, error parsing path: net.urllib.parse: failed parsing url
[vweb] tid: 001, error parsing path: net.urllib.parse: failed parsing url
[vweb] tid: 002, error parsing path: net.urllib.parse: failed parsing url
[vweb] tid: 004, error parsing path: net.urllib.parse: failed parsing url
[vweb] tid: 003, error parsing path: net.urllib.parse: failed parsing url
[vweb] tid: 005, error parsing path: net.urllib.parse: failed parsing url
[vweb] tid: 003, error parsing path: net.urllib.parse: failed parsing url
[vweb] tid: 000, error parsing path: net.urllib.parse: failed parsing url
[vweb] tid: 002, error parsing path: net.urllib.parse: failed parsing url

Possible Solution

No response

Additional Information/Context

Related to this gitly issue vlang/gitly#253

V version

V 0.4.4 4640627

Environment details (OS name and version, etc.)

V full version: V 0.4.4 aa28efc.4640627
OS: linux, Ubuntu 20.04.6 LTS
Processor: 8 cpus, 64bit, little endian, Intel(R) Core(TM) i7-3630QM CPU @ 2.40GHz

getwd: /home/bill/test
vexe: /home/bill/Documents/opt/v/v
vexe mtime: 2024-01-10 21:20:23

vroot: OK, value: /home/bill/Documents/opt/v
VMODULES: OK, value: /home/bill/.vmodules
VTMP: OK, value: /tmp/v_1000

Git version: git version 2.25.1
Git vroot status: weekly.2021.46-5307-g46406277
.git/config present: true

CC version: cc (Ubuntu 9.4.0-1ubuntu1~20.04.2) 9.4.0
thirdparty/tcc status: thirdparty-linux-amd64 12f392c3

Note

You can use the 👍 reaction to increase the issue's priority for developers.

Please note that only the 👍 reaction to the issue itself counts as a vote.
Other reactions and those to comments will not be taken into account.

@billpcs billpcs added the Bug This tag is applied to issues which reports bugs. label Jan 10, 2024
@billpcs
Copy link
Contributor Author

billpcs commented Jan 10, 2024

Some further information regarding the call hierarchy that leads to this error.

Inside vweb::handle_conn, a function named http.parse_request gets called, which is responsible to fill in the req.url field.

http.parse_request ends up calling http.parse_request_line that internally uses urllib.parse, our culprit.

The parsed value returned in req.url is once more parsed directly inside vweb::handle_conn

What happens is that req.url is filled with the empty string, which when parsed for the second time, returns the

eprintln('[vweb] tid: ${tid:03d}, error parsing path: ${err}')

A probable fix is this, inside urllib.parse_url

...
if rest == '//' {
  // do nothing, protect this special case
}
else if ((url.scheme != '' || !via_request) && !rest.starts_with('///')) && rest.starts_with('//') {
...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug This tag is applied to issues which reports bugs.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant