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

Fix templates which asset path points to external URL #1690

Merged
merged 1 commit into from
Sep 29, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions server/templates.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,11 @@ func loadTemplates(c webConfig, templatesDir string) (*templates, error) {
//assetPath is static/main.css
//relativeURL("/dex", "/dex/auth", "static/main.css") = "../static/main.css"
func relativeURL(serverPath, reqPath, assetPath string) string {
if u, err := url.ParseRequestURI(assetPath); err == nil && u.Scheme != "" {
Copy link
Member

Choose a reason for hiding this comment

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

Not sure if this is actually correct. //kubernetes.io/images/favicon.png would be perfectly valid HTML as well.

Copy link
Member Author

Choose a reason for hiding this comment

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

//kubernetes.io/images/favicon.png will be treated as a relative path because of the URL scheme is empty. Do you think we should limit the scheme to http/https instead?

Copy link
Member

Choose a reason for hiding this comment

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

//kubernetes.io/images/favicon.png is a valid URI and and I'm not sure it should be rewritten as a relative path.

Furthermore, Dex should usually be served over HTTPS, which means having an HTTP URL on the site will probably trigger browser security behavior.

TBH, that makes me think if supporting external URLs is a good idea in the first place.

Copy link
Member Author

Choose a reason for hiding this comment

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

I made this PR because:

  • It can be handy to use with prebuilt docker images from the official repo. You only need to specify one URL in the config to add an icon instead of adding it to the docker image.
  • It fixes the broken behavior. Someone might suffer because of such breaking changes.

But I agree with the concerns that you raised. Frankly, we need to make a decision here.

Copy link
Member

Choose a reason for hiding this comment

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

So after thinking about this for a looooooong time, I think we can assume that people should always use HTTPS URLs these days, so not supporting the schemaless URL should be fine. I'm also not concerned about using http urls on an https site: if someone does that, it's their problem.

Limiting the scheme, however, is an interesting question. Does that pose a security risk if we just allow using any schemes there? not sure.

// assetPath points to the external URL, no changes needed
return assetPath
}

splitPath := func(p string) []string {
res := []string{}
parts := strings.Split(path.Clean(p), "/")
Expand Down
7 changes: 7 additions & 0 deletions server/templates_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,13 @@ func TestRelativeURL(t *testing.T) {
assetPath: "assets/css/main.css",
expected: "../assets/css/main.css",
},
{
name: "external-url",
serverPath: "/dex",
reqPath: "/dex/auth/connector",
assetPath: "https://kubernetes.io/images/favicon.png",
expected: "https://kubernetes.io/images/favicon.png",
},
}

for _, test := range tests {
Expand Down