Skip to content

Added ALWAYS_RENDER_RAW_FILES option to the repository section #685

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
wants to merge 4 commits into from
Closed

Conversation

pgaskin
Copy link
Contributor

@pgaskin pgaskin commented Jan 17, 2017

Used for serving raw files with the right content type, instead of text/plain. Fixes (#683).

This option is disabled by default as it could be a potential security risk because the html in raw mode would render on the same domain as gitea.

@@ -772,6 +774,8 @@ please consider changing to GITEA_CUSTOM`)
if !filepath.IsAbs(Repository.Upload.TempPath) {
Repository.Upload.TempPath = path.Join(workDir, Repository.Upload.TempPath)
}

Repository.AlwaysRenderRawFiles = sec.Key("ALWAYS_RENDER_RAW_FILES").MustBool()
Copy link
Member

Choose a reason for hiding this comment

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

You need also update app.ini configuration.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@appleboy Done.

@@ -41,6 +44,7 @@ func ServeData(ctx *context.Context, name string, reader io.Reader) error {
return err
}


Copy link
Member

Choose a reason for hiding this comment

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

remove empty line.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

if base.IsTextFile(buf) || ctx.QueryBool("render") {
if setting.Repository.AlwaysRenderRawFiles {
ctx.Resp.Header().Set("Content-Disposition", fmt.Sprintf(`inline; filename="%s"`, name))
} else if base.IsTextFile(buf) || ctx.QueryBool("render") {
ctx.Resp.Header().Set("Content-Type", "text/plain; charset=utf-8")
} else if base.IsImageFile(buf) || base.IsPDFFile(buf) {
Copy link
Member

Choose a reason for hiding this comment

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

you should integrate this condition.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@appleboy I think it is more understandable this way.

@lunny lunny added this to the 1.1.0 milestone Jan 17, 2017
@lunny lunny added the type/feature Completely new functionality. Can only be merged if feature freeze is not active. label Jan 17, 2017
@tboerger
Copy link
Member

For reference: #683 (comment)

@tboerger tboerger added the lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. label Jan 17, 2017
@ghost
Copy link

ghost commented Feb 1, 2017

Hi. 👍 for merging this :)

@bkcsoft
Copy link
Member

bkcsoft commented Feb 6, 2017

I'm with @tboerger on this, this is a really bad idea...

@pgaskin
Copy link
Contributor Author

pgaskin commented Feb 6, 2017

@bkcsoft Some people like me really need this option. Maybe it could be a build tag, and not offer prebuild builds with this option?

@bkcsoft
Copy link
Member

bkcsoft commented Feb 12, 2017

@geek1011 well, if one has to compile it themselfs anyway, it could just be a patch-set outside the project, because this is a really bad idea and a huge security risk.

@lunny lunny modified the milestones: 1.x.x, 1.1.0 Feb 15, 2017
@lunny
Copy link
Member

lunny commented Feb 15, 2017

So let's move it to 1.x.x

@pgaskin
Copy link
Contributor Author

pgaskin commented Mar 2, 2017

Doesn't the csrf request token prevent this from being a security risk? If we make it not set the csrf cookie when sending the page, then wouldn't this be perfectly fine?

pgaskin and others added 4 commits March 8, 2017 20:37
Used for serving raw files with the right content type. Only enable if you know what you are doing.

Signed-off-by: Patrick G <[email protected]>
@strk
Copy link
Member

strk commented Mar 12, 2017

Sorry it's not clear to me what the security risk is. I understand is about running arbitrary javascript code embedded in HTML files put in a user repository. Now, cannot this be already done, only not by default ?

@pgaskin
Copy link
Contributor Author

pgaskin commented Mar 12, 2017

@strk I think it would be submitting a form to delete a user or something like that.

@rugk
Copy link
Contributor

rugk commented Mar 23, 2017

I understand is about running arbitrary javascript code embedded in HTML files put in a user repository.

Yes that's the issue…
CSRF tokens won't help since these are (as the name says) to protect from cross-site request forgeries, but here you are on the same site and an attacker can easily request a file with an CSRF token and extract it to use it in a request later.

Basically the attack is an XSS issue AFAIK. By opening a specific URL (with a file saved) untrusted code can be executed in the context of the Gitea installation. This can do anything…

So the fix is to disable it by default and if users need it add an option to enable parsing there. Even in Gogs it has been fixed already, so please don't get even slower than the original version. (Maybe also use the same config option for compatibility…)

Now, cannot this be already done, only not by default ?

Uh, no? I don't understand what you mean…

@strk
Copy link
Member

strk commented Mar 23, 2017 via email

@rugk
Copy link
Contributor

rugk commented Mar 23, 2017

(want to help us ?)

You already have this PR, so what?
Or just use the code/patch from Gogs…

Passing the render=1 parameter lets you receive HTML with arbitrary javascript embedded, already.

Exactly that's the behaviour that needs to be disabled (by default!).

@rugk
Copy link
Contributor

rugk commented Mar 23, 2017

Ah I saw that this PR does the opposite of fixing the render issue and should therefore be abolished.
Just as in gogs/gogs@b3c4a39 disable the rendering completely. Raw file means raw file meaning no parsing at all…

Of course you can allow users to use the render=1 parameter if the admin enables a special option. Or just remove it entirely - if admins really want to use it they could configure their reverse-proxy server to add/change the Content-Type header or so.

@strk
Copy link
Member

strk commented Mar 23, 2017 via email

@rugk
Copy link
Contributor

rugk commented Mar 23, 2017

I'll keep posting issues and complaining about security-stuff, be sure… 😊

@tboerger
Copy link
Member

I still don't like this option. This is something that should be handled by a Webserver. If the option is there, we will have users that enable it because they simply don't understand the risk. And than somebody will complain about it.

@rugk
Copy link
Contributor

rugk commented Mar 23, 2017

Then remove it entirely…

@strk
Copy link
Member

strk commented Mar 23, 2017

I think there are valid use cases where the security implication is not a concern: private hosting with only trusted users. For those cases, it's ok to let the admin allow rendering (even by default) the content. This is @geek1011 usecase, I think.

@rugk
Copy link
Contributor

rugk commented Mar 24, 2017

Yes, but as @tboerger says, just use a reverse-proxy and add/modify then headers. There is no need to have this option in Gitea. (Users could not be aware of the risk ad enable it more or less accidentally or for just trying it out etc.)

On the other hand there is of course no need to discuss this. I am fine with an option, but please, please, disable it by default finally.

@tboerger
Copy link
Member

@lunny? @bkcsoft? I'm against this option.

@pgaskin
Copy link
Contributor Author

pgaskin commented Mar 24, 2017 via email

@bkcsoft
Copy link
Member

bkcsoft commented Apr 18, 2017

General concensus seems to be that this is a bad idea all together, so I'm closing this 🙂

Feel free to reopen if someone wants to discuss it further

@bkcsoft bkcsoft closed this Apr 18, 2017
@lunny lunny removed this from the 1.x.x milestone Apr 18, 2017
@rugk
Copy link
Contributor

rugk commented Apr 18, 2017

So can we now implement/disable the rendering properly?

@strk
Copy link
Member

strk commented Apr 18, 2017 via email

@rugk
Copy link
Contributor

rugk commented Apr 18, 2017

Great idea!

@bkcsoft
Copy link
Member

bkcsoft commented Apr 19, 2017

@strk I'm fine with that proposal 🙂

@strk
Copy link
Member

strk commented Apr 19, 2017 via email

@go-gitea go-gitea locked and limited conversation to collaborators Nov 23, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. type/feature Completely new functionality. Can only be merged if feature freeze is not active.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants