Skip to content

Slashes in folder param become escaped #1351

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

Closed
Merith-TK opened this issue Feb 10, 2020 · 24 comments
Closed

Slashes in folder param become escaped #1351

Merith-TK opened this issue Feb 10, 2020 · 24 comments
Labels
bug Something isn't working

Comments

@Merith-TK
Copy link
Contributor

Version: 1.41.1
Commit: f51e045cd5483561afc07694f39307fb673b6d1d
Date: 2020-01-17T22:58:55.612Z
Browser: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.130 Safari/537.36
Code Server Version: 2.1698-vsc1.41.1
  • OS Version: archlinux

Description

When changing directories, it becomes
https://code.example.com/?folder=vscode-remote%3A%2F%2Fcode.example.com%2Fhome%2Fdeveloper%2FWorkspace%2FDND
instead of `https://code.example.com/?folder=/home/developer/Workspace/

Steps to Reproduce

  1. open folder as default (accessible at https://example.com/)
  2. CTRL+k and CTRL+O and open a different folder
  3. check url
@Merith-TK Merith-TK added the bug Something isn't working label Feb 10, 2020
@Merith-TK
Copy link
Contributor Author

yes i know the name of the issue is horrible, my words have been failing me today

@nhooyr nhooyr changed the title Url changes to non-standard output when changing directories Slases in folder param become escaped for no reason Feb 11, 2020
@nhooyr
Copy link
Contributor

nhooyr commented Feb 11, 2020

Fixed :)

Thanks for reporting, I confirmed this.

@nhooyr nhooyr changed the title Slases in folder param become escaped for no reason Slashes in folder param become escaped Feb 11, 2020
@Merith-TK
Copy link
Contributor Author

Yeah, also whats with the ?folder=vscode-remote%3A%2F%2Fcode.example.com%2F instead of ?folder=/

I dont understand why it does this?

@nhooyr
Copy link
Contributor

nhooyr commented Feb 11, 2020

Not sure either. cc @code-asher.

@code-asher
Copy link
Member

I'm not certain, that just seems to be what VS Code 1.41.1 is doing now.

@code-asher
Copy link
Member

code-asher commented Feb 11, 2020

To clarify, if you click file > open that's what VS Code puts in the URL, so I updated our server code to match.

@Merith-TK
Copy link
Contributor Author

i think it may be because of the implementation?
This suggests that code-server uses a varient of the vscode-remote extension and wasnt properly modifed

@code-asher
Copy link
Member

code-asher commented Feb 11, 2020

Internally VS Code refers to remote files with the vscode-remote:// scheme. In our case the remote provider is code-server but that doesn't change the scheme that VS Code uses. We could change it (and we used to) but there didn't seem any benefit in the added patching it required.

@Merith-TK
Copy link
Contributor Author

Ah, alright then,

@coadler
Copy link
Contributor

coadler commented Feb 11, 2020

Aren't slashes supposed to be URL encoded in query strings?

@nhooyr
Copy link
Contributor

nhooyr commented Feb 11, 2020

It's optional.

package main

import (
	"fmt"
	"net/url"
)

func main() {
	u, _ := url.Parse("localhost:8080/?meow=bar/foo&big=coadler/asher")
	fmt.Println(u.Query())
}

Prints:

map[big:[coadler/asher] meow:[bar/foo]]

@coadler
Copy link
Contributor

coadler commented Feb 11, 2020

That's true it parses, but there'd be no way to construct the same thing on the way out

package main

import (
	"fmt"
	"net/url"
)

func main() {
	u, err := url.ParseQuery("meow=bar/foo&big=coadler/asher")
	if err != nil {
		panic(err)
	}
	
	fmt.Println(u)
	fmt.Println(u.Encode())
}
map[big:[coadler/asher] meow:[bar/foo]]
big=coadler%2Fasher&meow=bar%2Ffoo

https://tools.ietf.org/html/rfc2396#section-3.4 seems to indicate slashes are reserved within query strings

The documentation for ParseQuery says that it expects a URL-encoded query string but seems to work fine if it doesn't
https://golang.org/src/net/url/url.go?s=25201:25246#L859

@nhooyr
Copy link
Contributor

nhooyr commented Feb 11, 2020

That's interesting. So then everything is working as expected.

@code-asher Why does the folder argument need the scheme when it's always vscode-remote? Let's just remove it and add it ourselves when appropriate?

@code-asher
Copy link
Member

code-asher commented Feb 12, 2020 via email

code-asher added a commit that referenced this issue Feb 12, 2020
When using a query parameter without a scheme, the scheme defaults to
`file`. This results in the files in the explorer being technically
different from the file picker files because they are file:// instead of
vscode-remote://, causing the same file to open twice and causing
numerous issues.

Normally the file explorer wouldn't even load at all in this case but we
provide a file service for file:// URLs as a failsafe for certain files
that wouldn't load correctly in the past. These files load fine now
using the vscode-remote scheme, so I'm also removing that service.

Related: #1351.
Fixes #1294.
@JtMotoX
Copy link

JtMotoX commented Mar 10, 2020

I navigate many times by manually editing the url to open the folder I want. It also helps me easily see the directory that I am currently in, since many times I will have 5 tabs open with different directories. The new vscode-remote:// URL has been pretty annoying. I wish there were a way to keep the folder= URL or at least an option or parameter we can pass when launching code-server.

Workaround to give you the old url functionality back:
My code-server instance sits behind a nginx reverse proxy with Let's Encrypt SSL and a secure username+pwd login form. If anyone has their instance behind an nginx reverse proxy, you can add the configuration lines below to your nginx configs which will strip out the vscode-remote:// and replace the characters with slashes which will give you the url format that we are all used to. Each additional line will support 1 subdirectory deep, so my configs below will support 12 subfolders deep. There may be a better way of doing this but I am new to nginx and only have about 10 hours of experience with it, 2 of which were spent trying to solve this.

This:
https://my.domain.com/?folder=vscode-remote%3A%2F%2Fmyhostname%2FUsers%2Fusername%2Ffolder1%2Ffolder2%2Ffolder3
Becomes This:
https://my.domain.com/?folder=/Users/username/folder1/folder2/folder3

    set $args_original $args;
    if ($args ~ ^(folder=)vscode-remote%3A%2F%2F.*?%2F(.*)$) { set $args $1/$2; }
    if ($args ~ ^(folder=.*)%2F(.*)$) { set $args $1/$2; }
    if ($args ~ ^(folder=.*)%2F(.*)$) { set $args $1/$2; }
    if ($args ~ ^(folder=.*)%2F(.*)$) { set $args $1/$2; }
    if ($args ~ ^(folder=.*)%2F(.*)$) { set $args $1/$2; }
    if ($args ~ ^(folder=.*)%2F(.*)$) { set $args $1/$2; }
    if ($args ~ ^(folder=.*)%2F(.*)$) { set $args $1/$2; }
    if ($args ~ ^(folder=.*)%2F(.*)$) { set $args $1/$2; }
    if ($args ~ ^(folder=.*)%2F(.*)$) { set $args $1/$2; }
    if ($args ~ ^(folder=.*)%2F(.*)$) { set $args $1/$2; }
    if ($args ~ ^(folder=.*)%2F(.*)$) { set $args $1/$2; }
    if ($args ~ ^(folder=.*)%2F(.*)$) { set $args $1/$2; }
    if ($args ~ ^(folder=.*)%2F(.*)$) { set $args $1/$2; }
    if ($args != $args_original) {
        return 301 "$scheme://${http_host}$uri?$args";
    }

@code-asher
Copy link
Member

code-asher commented Mar 10, 2020 via email

@Merith-TK
Copy link
Contributor Author

how easy would that patch be?

@code-asher
Copy link
Member

code-asher commented Mar 11, 2020 via email

@code-asher
Copy link
Member

code-asher commented Mar 11, 2020 via email

@JtMotoX
Copy link

JtMotoX commented Mar 11, 2020

That sounds great!

@JtMotoX
Copy link

JtMotoX commented Mar 11, 2020

I imagine it would be a single line change

30 lines later...

closed this in 26647c5

Thanks Asher! 👏

@code-asher
Copy link
Member

I think we're going to need to revert this (at least re-introduce the encoding) because otherwise you can't open directories with #, &, etc to name a few.

@code-asher
Copy link
Member

Hmm maybe we can decode just the slashes after encoding (.replace("%2F", "/")). Seems to work but I'm not sure if there's some case I'm not considering.

@t-d-d
Copy link

t-d-d commented Apr 6, 2020

@code-asher and can't open paths with spaces which is fairly common. See #1488

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
None yet
Development

No branches or pull requests

6 participants