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

Webbundle should set mimetype of config.js correctly #248

Closed
lilioid opened this issue Oct 30, 2020 · 6 comments · Fixed by #249
Closed

Webbundle should set mimetype of config.js correctly #248

lilioid opened this issue Oct 30, 2020 · 6 comments · Fixed by #249
Labels
bug Something isn't working

Comments

@lilioid
Copy link
Contributor

lilioid commented Oct 30, 2020

What happened:
When opening the Web-UI, only a blank page showed.

What you expected to happen:
The Web-UI should work as expected or at least show an error that it's config could not be loaded.

How to reproduce it (as minimally and precisely as possible):

  • Set the Header X-Content-Type-Options: nosniff on your webserver
  • Proxy the Agola Web-UI through said webserver

Anything else we need to know?:
When the X-Content-Type-Option nosniff is set, it instructs browsers to not guess any content MIME-Types and since the /config.js route does not define its content to be Javascript, it does not get interpreted as such.
Setting the response header Content-Type to application/javascript below should fix this problem:

if r.URL.Path == "/config.js" {
_, err := w.Write(config)
if err != nil {
http.Error(w, "", http.StatusInternalServerError)
}
return

Environment:

  • Agola version: v0.5.0 (bug is still present in master though)
@lilioid lilioid added the bug Something isn't working label Oct 30, 2020
@sgotti
Copy link
Member

sgotti commented Oct 30, 2020

@ftsell does this issue happens only if config.js is invalid javascript right?

We never saw such issue with a valid config.js so I'm not sure if this is the real issue.

@lilioid
Copy link
Contributor Author

lilioid commented Oct 30, 2020

No the validity of config.js does not matter because this issue appears before the file is even considered javascript (by the Browser).

Basically the Browser is trying to figure out as what to treat the received HTTP-Response. Normally it would look at the Content-Type header and if that is not present, try to guess by looking at the content (taking into account file extension and such). This secondary behavior is called sniffing and can be disabled (as I have done).

And in this circumstance neither sniffing nor a server-defined MIME-Type is available so the Browser treats config.js as plain text instead of executing it as Javascript.

Mozilla explains this in their article about MIME-Type in more detail.

@sgotti
Copy link
Member

sgotti commented Oct 30, 2020

@ftsell but are you using a custom config.js? By default no config.js is provided and everything works correctly. config.js is needed only under some special circumstances. Can you provide a way to reproduce this issue?

@lilioid
Copy link
Contributor Author

lilioid commented Oct 30, 2020

No I am not using a custom config.js.

And testing things with a locally running agola server works for me as well because then the X-Content-Type-Options Header is not set. My production webserver does set this Header though.
I have also tested enabling and disabling the nosniff option through X-Content-Type-Options and can verify that this resulted in the web-ui working and not-working. Because of that I am fairly certain that this is the cause of the issue.

If you want to, you can check out the browser console when visiting my deployed instance over at agola-ci.finn-thorben.me
image

In this Gist you can also find the exact deployment config I am currently using (on Kubernetes).

@sgotti
Copy link
Member

sgotti commented Oct 30, 2020

@ftsell thanks. So probably our production webserver is not setting that header. Would you like to open a pull request?

@lilioid
Copy link
Contributor Author

lilioid commented Oct 30, 2020

I'm working on a PR as we speak ;)

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

Successfully merging a pull request may close this issue.

2 participants