b01dce2a6e added support for `RENDER_CONTENT_MODE=iframe` which used `onload="this.height=this.contentWindow.document.documentElement.scrollHeight"` to set the height of the iframe to the height of the embedded document.
Unfortunately, while this might have worked at some point, with `sandbox="allow-scripts"`, the document embedded in the iframe is counted as a cross-origin document, and browsers prevent any access to cross-origin documents.
[The solution](https://stackoverflow.com/questions/8223239/how-to-get-height-of-iframe-cross-domain) is to instead use `window.postMessage` to pass the height from the embedded document back to the embedding page.
Would appreciate a review of the privacy implications of this change—I feel it's probably "okay", but I'm not convinced my analysis is perfect.
Resolves#7586
Manual test:
1. Add the following snippet to your `app.ini`:
```ini
[markup.html]
ENABLED = true
FILE_EXTENSIONS = .html
RENDER_COMMAND = cat
RENDER_CONTENT_MODE = iframe
NEED_POSTPROCESS = false
```
2. Create a file in a repository with the name `test.html` and with the following contents:
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8"/>
</head>
<body>
Hi from iframe!
Here is a random number: <script>document.write(Math.random())</script>.
</body>
</html>
```
3. Go to the file.
4. Observe the HTML is rendered and that the height is not larger than it needs to be (38 pixels).
Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/8378
Reviewed-by: Gusted <gusted@noreply.codeberg.org>
Co-authored-by: Bojidar Marinov <bojidar.marinov.bg@gmail.com>
Co-committed-by: Bojidar Marinov <bojidar.marinov.bg@gmail.com>
Hi there! Tired of big platforms playing monopoly?
Providing Git hosting for your project, friends, company or community?
Forgejo (/for'd͡ʒe.jo/ inspired by forĝejo – the Esperanto word for forge) has you covered with its intuitive interface,
light and easy hosting and a lot of built-in functionality.
Forgejo was created in 2022
because we think that the project should be owned by an independent community.
If you second that, then Forgejo is for you!
Our promise: Independent Free/Libre Software forever!
What does Forgejo offer?
If you like any of the following, Forgejo is literally meant for you:
Lightweight: Forgejo can easily be hosted on nearly every machine.
Running on a Raspberry? Small cloud instance? No problem!
Project management: Besides Git hosting, Forgejo offers issues,
pull requests, wikis, kanban boards and much more to coordinate with your team.
Publishing: Have something to share? Use releases to host your software for download,
or use the package registry to publish it for docker, npm and many other package managers.
Customizable: Want to change your look? Change some settings?
There are many config switches to make Forgejo work exactly like you want.
Powerful: Organizations & team permissions, CI integration, Code Search, LDAP, OAuth and much more.
If you have advanced needs, Forgejo has you covered.
Privacy: From update checker to default settings: Forgejo is built to be privacy first for you and your crew.
Federation: (WIP) We are actively working to connect software forges with each other through ActivityPub,
and create a collaborative network of personal instances.
Forgejo is distributed under the terms of the GPL version 3.0 or any later version.
The agreement for this license was documented in June 2023 and implemented during the development of Forgejo v9.0. All Forgejo versions before v9.0 are distributed under the MIT license.
Get involved
If you are interested in making Forgejo better, either by reporting a bug or by changing the governance, please take a look at the contribution guide.