Codeberg/Community
54
325
Fork
You've already forked Community
12

HTML in Markdown doesn't work #1886

Closed
opened 2025年04月25日 09:44:59 +02:00 by Ghost · 11 comments

Comment

Why HTML in Markdown doesn't work in codeberg?

### Comment Why HTML in Markdown doesn't work in codeberg?

What do you mean it does not work? Personally I have pieces of HTML in most of my project's READMEs and it works well

What do you mean it does not work? Personally I have pieces of HTML in most of my project's READMEs and it works well

Example:

# MDHacks

<a href="https://nogithub.codeberg.page">
 <img src="https://nogithub.codeberg.page/badge.svg" alt="Please don't upload to GitHub"></img>
</a>
<p>Fun markdown's hacks</p>
Hi, **MDHacks** is a repository that contain multiple & only markdown hacks!
For example, here it's a markdown hack:
<p id="body" type="text/html" style="font-weight:bold;font-style:italic;background-color:green;color:lightgreen;">
This is a markdown's hack.
</p>
## FAQ

❓How that works?
💡This works using **HTML, CSS** & pottentialy **JavaScript** because it's compactible with **Markdown**.
❓How to made this?
💡 To create your own markdown's hack, you need to make a HTML & CSS like...
`<p id="body" type="text/html" style="font-wegith:bold;font-style:italic;background:green;color:lightgreen;>Your text</p>`. For informations, always start a paragraph with `<p id="body" type="text/html" style="opacity: 0%;">AAAAAA</p>` as the document body.
Or another, you cannot use the `<style>` tag in **Markdown**, but in place, use the `style` argument inside your element.

More informations at https://codeberg.org/therealneca7/mdhacks.

Example: ```markdown # MDHacks <a href="https://nogithub.codeberg.page"> <img src="https://nogithub.codeberg.page/badge.svg" alt="Please don't upload to GitHub"></img> </a> <p>Fun markdown's hacks</p> Hi, **MDHacks** is a repository that contain multiple & only markdown hacks! For example, here it's a markdown hack: <p id="body" type="text/html" style="font-weight:bold;font-style:italic;background-color:green;color:lightgreen;"> This is a markdown's hack. </p> ## FAQ ❓How that works? 💡This works using **HTML, CSS** & pottentialy **JavaScript** because it's compactible with **Markdown**. ❓How to made this? 💡 To create your own markdown's hack, you need to make a HTML & CSS like... `<p id="body" type="text/html" style="font-wegith:bold;font-style:italic;background:green;color:lightgreen;>Your text</p>`. For informations, always start a paragraph with `<p id="body" type="text/html" style="opacity: 0%;">AAAAAA</p>` as the document body. Or another, you cannot use the `<style>` tag in **Markdown**, but in place, use the `style` argument inside your element. ``` More informations at <https://codeberg.org/therealneca7/mdhacks>.

Yes, CSS and JS can't be injected because of the server CSP headers if I'm correct. It would open a huge attack surface otherwise.

Yes, CSS and JS can't be injected because of the server CSP headers if I'm correct. It would open a huge attack surface otherwise.

Why that will open a huge attack surface?

Why that will open a huge attack surface?

@therealneca7 wrote in #1886 (comment):

Why that will open a huge attack surface?

Well, if you can include custom scripts in your markdown files, this means that you can execute arbitrary code in the browser of anyone visiting the page that renders your markdown file (which is precisely what CSP aims to prevent).
Similarly, if CSS is allowed outside of inline definitions, it is possible to completely break the layout of the page, since you can define CSS rules for body or other HTML elements.

@therealneca7 wrote in https://codeberg.org/Codeberg/Community/issues/1886#issuecomment-4021715: > Why that will open a huge attack surface? Well, if you can include custom scripts in your markdown files, this means that you can execute arbitrary code in the browser of anyone visiting the page that renders your markdown file (which is precisely what CSP aims to prevent). Similarly, if CSS is allowed outside of inline definitions, it is possible to completely break the layout of the page, since you can define CSS rules for `body` or other HTML elements.

kind, a markdown file that inject HyperText Markup Language, Cascading Style Sheets and JavaScript, which makes a custom page in the even website, even subdomain, even link?

kind, a markdown file that inject HyperText Markup Language, Cascading Style Sheets and JavaScript, which makes a custom page in the even website, even subdomain, even link?

You can edit a custom page (i.e. codeberg.page) any way you want, but you can't do whatever you like with the md render inside codeberg.org. And yes you can have a custom page, even subdomain with a custom domain. see https://docs.codeberg.org/codeberg-pages/using-custom-domain/

You can edit a custom page (i.e. codeberg.page) any way you want, but you can't do whatever you like with the md render inside codeberg.org. And yes you can have a custom page, even subdomain with a custom domain. see https://docs.codeberg.org/codeberg-pages/using-custom-domain/

no kind in https://codeberg.org/example-user/example-repo (thats a example account & example repository created by me) and the README.md injects HTML, CSS & JavaScript. It is possible?

no kind in <https://codeberg.org/example-user/example-repo> (thats a example account & example repository created by me) and the `README.md` injects HTML, CSS & JavaScript. It is possible?

@therealneca7 wrote in #1886 (comment):

no kind in https://codeberg.org/example-user/example-repo (thats a example account & example repository created by me) and the README.md injects HTML, CSS & JavaScript. It is possible?

I don't think so. You can, of course, use inline style definitions, but more than that would cause many security concerns, as explained here. For instance, imagine, if you had the following line in your README.md:

<style>
body {
 display: none !important;
}
</style>

It would make the whole page disappear every time someone clicks on your repository! And you could do much more damage by injecting JavaScript, since it would execute actual code every time the page that renders your README is loaded.

@therealneca7 wrote in https://codeberg.org/Codeberg/Community/issues/1886#issuecomment-4061237: > no kind in https://codeberg.org/example-user/example-repo (thats a example account & example repository created by me) and the `README.md` injects HTML, CSS & JavaScript. It is possible? I don't think so. You can, of course, use inline style definitions, but more than that would cause many security concerns, as [explained here](https://codeberg.org/Codeberg/Community/issues/1886#issuecomment-4025357). For instance, imagine, if you had the following line in your README.md: ```html <style> body { display: none !important; } </style> ``` It would make the whole page disappear every time someone clicks on your repository! And you could do much more damage by injecting JavaScript, since it would execute actual code every time the page that renders your README is loaded.

With JS injection, you could get user cookies, ouath, mining cryptocurrency, etc. so yes as @camelia said, not a good idea. If you want all of that use Codeberg's page https://codeberg.page/

With JS injection, you could get user cookies, ouath, mining cryptocurrency, etc. so yes as @camelia said, not a good idea. If you want all of that use Codeberg's page https://codeberg.page/

Okay. I will close this issue now.

Okay. I will close this issue now.
Sign in to join this conversation.
No Branch/Tag specified
main
No results found.
Labels
Clear labels
accessibility

Reduces accessibility and is thus a "bug" for certain user groups on Codeberg.
bug

Something is not working the way it should. Does not concern outages.
bug
infrastructure

Errors evidently caused by infrastructure malfunctions or outages
Codeberg

This issue involves Codeberg's downstream modifications and settings and/or Codeberg's structures.
contributions welcome

Please join the discussion and consider contributing a PR!
docs

No bug, but an improvement to the docs or UI description will help
duplicate

This issue or pull request already exists
enhancement

New feature
infrastructure

Involves changes to the server setups, use `bug/infrastructure` for infrastructure-related user errors.
legal

An issue directly involving legal compliance
licence / ToS

involving questions about the ToS, especially licencing compliance
please chill
we are volunteers

Please consider editing your posts and remember that there is a human on the other side. We get that you are frustrated, but it's harder for us to help you this way.
public relations

Things related to Codeberg's external communication
question

More information is needed
question
user support

This issue contains a clearly stated problem. However, it is not clear whether we have to fix anything on Codeberg's end, but we're helping them fix it and/or find the cause.
s/Forgejo

Related to Forgejo. Please also check Forgejo's issue tracker.
s/Forgejo/migration

Migration related issues in Forgejo
s/Pages

Issues related to the Codeberg Pages feature
s/Weblate

Issue is related to the Weblate instance at https://translate.codeberg.org
s/Woodpecker

Woodpecker CI related issue
security

involves improvements to the sites security
service

Add a new service to the Codeberg ecosystem (instead of implementing into Gitea)
upstream

An open issue or pull request to an upstream repository to fix this issue (partially or completely) exists (i.e. Gitea, Forgejo, etc.)
wontfix

Codeberg's current set of contributors are not planning to spend time on delegating this issue.
Milestone
Clear milestone
No items
No milestone
Projects
Clear projects
No items
No project
Assignees
Clear assignees
No assignees
3 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Codeberg/Community#1886
Reference in a new issue
Codeberg/Community
No description provided.
Delete branch "%!s()"

Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?