Skip to content

Add new RENDER_CONTENT_IFRAME_SANDBOX for the iframe sandbox when load html, Add RENDER_CONTENT_EXTERNAL_CSP for the external render Content-Security-Policy header #20180

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

Draft
wants to merge 12 commits into
base: main
Choose a base branch
from

Conversation

lunny
Copy link
Member

@lunny lunny commented Jun 30, 2022

When render with RENDER_CONTENT_MODE with iframe, it in fact cannot render correct because the url of iframe is the same origin of parent window url. This PR adds new RENDER_CONTENT_IFRAME_SANDBOX for the iframe sandbox when load html, Add RENDER_CONTENT_EXTERNAL_CSP for the external render Content-Security-Policy header

@lunny lunny added this to the 1.18.0 milestone Jun 30, 2022
@lunny lunny added the skip-changelog This PR is irrelevant for the (next) changelog, for example bug fixes for unreleased features. label Jun 30, 2022
@lunny lunny requested review from lafriks, delvh and wxiaoguang June 30, 2022 08:04
@wxiaoguang
Copy link
Contributor

My thought is: there could be two options (one RENDER_CONTENT_IFRAME_SANDBOX for the iframe sandbox, one RENDER_CONTENT_EXTERNAL_CSP for the external render Content-Security-Policy header).

Then users can customize everything if they want, they pay attention for their security and risks.

@GiteaBot GiteaBot added the lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. label Jun 30, 2022
@lunny
Copy link
Member Author

lunny commented Jul 19, 2022

My thought is: there could be two options (one RENDER_CONTENT_IFRAME_SANDBOX for the iframe sandbox, one RENDER_CONTENT_EXTERNAL_CSP for the external render Content-Security-Policy header).

Then users can customize everything if they want, they pay attention for their security and risks.

Is that really necessary to have so many options for users?

@wxiaoguang
Copy link
Contributor

Because there are even more options for sandbox and Content-Security-Policy. I do not think it's possible to enumerate all possibilities by introducing fixed options on Gitea side.

@lunny
Copy link
Member Author

lunny commented Jul 30, 2022

Because there are even more options for sandbox and Content-Security-Policy. I do not think it's possible to enumerate all possibilities by introducing fixed options on Gitea side.

Done.

@lunny lunny changed the title Add new RENDER_CONTENT_MODE value iframe-allow-same-origin to allow load html Add new RENDER_CONTENT_IFRAME_SANDBOX for the iframe sandbox when load html, Add RENDER_CONTENT_EXTERNAL_CSP for the external render Content-Security-Policy header Jul 30, 2022
@wxiaoguang

This comment was marked as outdated.

@wxiaoguang wxiaoguang force-pushed the lunny/fix_html_render branch from b49aeed to 73dde8b Compare August 8, 2022 10:39
@wxiaoguang
Copy link
Contributor

This issue seems more complex than it looks like. More information here:

By default, the allow-same-origin should not be used, otherwise the attacker can render a malicious JS to do web requests as current user.

Since there is no allow-same-origin, then the parent iframe can not read the embedded document height directly, then there should be some JS code using postMessage to pass the height to parent to do the resize.

And there is no direct access to templates, so it's not easy to render the HTML and JS code by tmpl files, at the moment the HTML and JS code are embedded in Go code directly, which makes the code look hacky.

According to lunny, this PR could be set to WIP

@lunny
Copy link
Member Author

lunny commented Sep 8, 2022

@wxiaoguang Do you have further questions?

@wxiaoguang
Copy link
Contributor

I didn't have any question. You suggested to put it in WIP.

@lunny
Copy link
Member Author

lunny commented Sep 8, 2022

I didn't have any question. You suggested to put it in WIP.

Yes, in that time. But now I think maybe we could consider to merge it.

@lunny lunny mentioned this pull request Sep 15, 2022
@lunny lunny modified the milestones: 1.18.0, 1.19.0 Oct 26, 2022
@lunny lunny requested a review from KN4CK3R December 12, 2022 03:36
@lunny lunny modified the milestones: 1.19.0, 1.20.0 Feb 1, 2023
@andrepearce
Copy link

What happen to this change? Is there any reason why it seems things have gone stale? As I think we are running into this exact issue currently.

@wxiaoguang
Copy link
Contributor

wxiaoguang commented Apr 20, 2023

I think the reason is:

  • No real requirement before, no motivation, and I was told to put it in WIP after I made some tries, so I didn't spent more time on it.
  • No 100% perfect solution for resizing external iframe, it needs to append JS code after the external </html>, so it would cause arguments and have obstacles, although I think it is fine.

@wxiaoguang wxiaoguang removed this from the 1.20.0 milestone May 27, 2023
@lunny lunny added kind/bugfix and removed type/bug labels Oct 7, 2023
@delvh delvh added type/bug and removed kind/bugfix labels Oct 7, 2023
@lunny lunny marked this pull request as draft October 11, 2024 18:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. skip-changelog This PR is irrelevant for the (next) changelog, for example bug fixes for unreleased features. type/bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants