[GH-ISSUE #268] Support Content-Type: text/html #210

Closed
opened 2026-05-07 00:21:35 +02:00 by BreizhHardware · 7 comments

Originally created by @unai-ndz on GitHub (May 22, 2022).
Original GitHub issue: https://github.com/binwiederhier/ntfy/issues/268

I'm trying to send an html file as an attachment.

This does not work, only the first 4 characters get sent.

curl \
  -H "Title: Service failed" \
  -H "Filename: log.html" \
  -T file.html  \
  -d "service" \
  ntfy.sh/test

This works, but when opening the file it gets opened as a normal text file without rendering the html (When opening the link https://ntfy.sh/file/example.html) or browser apps are not available in the list of apps to open it (Android)

cat file.html | curl \
  -H "Title: Service failed" \
  --include \
  -H "Filename: log.html" \
  -H 'Content-Type: text/html' \
  --data @- \
  -d "service" \
  ntfy.sh/test

I'm doing something wrong?

Originally created by @unai-ndz on GitHub (May 22, 2022). Original GitHub issue: https://github.com/binwiederhier/ntfy/issues/268 I'm trying to send an html file as an attachment. This does not work, only the first 4 characters get sent. ```bash curl \ -H "Title: Service failed" \ -H "Filename: log.html" \ -T file.html \ -d "service" \ ntfy.sh/test ``` This works, but when opening the file it gets opened as a normal text file without rendering the html (When opening the link `https://ntfy.sh/file/example.html`) or browser apps are not available in the list of apps to open it (Android) ```bash cat file.html | curl \ -H "Title: Service failed" \ --include \ -H "Filename: log.html" \ -H 'Content-Type: text/html' \ --data @- \ -d "service" \ ntfy.sh/test ``` I'm doing something wrong?
BreizhHardware 2026-05-07 00:21:35 +02:00
Author
Owner

@binwiederhier commented on GitHub (May 22, 2022):

The fact that the PUT doesn't work is very dubious. Maybe show the curl details with -v?

The fact that the HTML is not rendered is a feature, not a big ;-) Rendering untrusted HTML in the browser is a huge security risk: https://github.com/binwiederhier/ntfy/blob/main/util/content_type_writer.go#L28

I suppose on your own server that kogix does not apply anymore, though. Is this your own server? I suppose I could make this a flag in the config if this is important to you.

<!-- gh-comment-id:1133865845 --> @binwiederhier commented on GitHub (May 22, 2022): The fact that the PUT doesn't work is very dubious. Maybe show the curl details with -v? The fact that the HTML is not rendered is a feature, not a big ;-) Rendering untrusted HTML in the browser is a huge security risk: https://github.com/binwiederhier/ntfy/blob/main/util/content_type_writer.go#L28 I suppose on your own server that kogix does not apply anymore, though. Is this your own server? I suppose I could make this a flag in the config if this is important to you.
Author
Owner

@unai-ndz commented on GitHub (May 22, 2022):

I figured out the issue with PUT. When providing the -d option the attachment also gets Content-Length: $lenght_of_d.
When adding an attachment the message gets replaced by You received a file anyways so it's useless to set both.

Right now I'm just testing it but if I will self-host if I keep using it.

I would argue that if you trust the app you may as well trust the server but I agree that some nasty things could be done so security wise seems reasonable.

I suppose I could make this a flag in the config
That would be nice but if it's just for me maybe it's not worth it.
I'm gonna leave it open for now but feel free to close this if there is not a lot of interest.

Alternatives:

  • Check gotify as it supports markdown messages.
  • Self-host the html and ntfy the link (Needs to deal with authentication but I'm planing on setting up a VPN anyways)
<!-- gh-comment-id:1133938642 --> @unai-ndz commented on GitHub (May 22, 2022): I figured out the issue with PUT. When providing the `-d` option the attachment also gets `Content-Length: $lenght_of_d`. When adding an attachment the message gets replaced by `You received a file` anyways so it's useless to set both. Right now I'm just testing it but if I will self-host if I keep using it. I would argue that if you trust the app you may as well trust the server but I agree that some nasty things could be done so security wise seems reasonable. > I suppose I could make this a flag in the config That would be nice but if it's just for me maybe it's not worth it. I'm gonna leave it open for now but feel free to close this if there is not a lot of interest. Alternatives: - Check gotify as it supports markdown messages. - Self-host the html and ntfy the link (Needs to deal with authentication but I'm planing on setting up a VPN anyways)
Author
Owner

@binwiederhier commented on GitHub (May 22, 2022):

Just looked at the curl again. You cannot do -d and -T at the same time. You can only set the body once. If you want to set the message and upload a file, you can do -H "Message: My message" (header) or ?message=My+message (query param). All parameters can be headers or query parameters (see https://ntfy.sh/docs/publish/#list-of-all-parameters)

<!-- gh-comment-id:1133949681 --> @binwiederhier commented on GitHub (May 22, 2022): Just looked at the `curl` again. You cannot do `-d` and `-T` at the same time. You can only set the body once. If you want to set the message and upload a file, you can do `-H "Message: My message"` (header) or `?message=My+message` (query param). All parameters can be headers or query parameters (see https://ntfy.sh/docs/publish/#list-of-all-parameters)
Author
Owner

@binwiederhier commented on GitHub (May 22, 2022):

Check gotify as it supports markdown messages.

Are you just trying to format the message? Then an attachment is definitely not the right thing to do.

<!-- gh-comment-id:1133949824 --> @binwiederhier commented on GitHub (May 22, 2022): > Check gotify as it supports markdown messages. Are you just trying to format the message? Then an attachment is definitely not the right thing to do.
Author
Owner

@unai-ndz commented on GitHub (May 23, 2022):

Sorry for the bother with curl, I don't use it very often.

Formating the message is what I was looking for but tried to use attachments as a compromise. nfty looks pretty good so I was trying to make it work.

<!-- gh-comment-id:1134734983 --> @unai-ndz commented on GitHub (May 23, 2022): Sorry for the bother with curl, I don't use it very often. Formating the message is what I was looking for but tried to use attachments as a compromise. nfty looks pretty good so I was trying to make it work.
Author
Owner

@binwiederhier commented on GitHub (May 23, 2022):

If Markdown (bold, italics, underline, link) is enough, I'm happy to implement this. Maybe create a new ticket and close this one if you'd like that. I'm sure other people would like Markdown support too.

<!-- gh-comment-id:1134779658 --> @binwiederhier commented on GitHub (May 23, 2022): If Markdown (bold, italics, underline, link) is enough, I'm happy to implement this. Maybe create a new ticket and close this one if you'd like that. I'm sure other people would like Markdown support too.
Author
Owner

@binwiederhier commented on GitHub (May 27, 2022):

As I said, please feel free to create another ticket for Markdown support. I'm closing this ticket. Thank you for using ntfy 👍

<!-- gh-comment-id:1139562427 --> @binwiederhier commented on GitHub (May 27, 2022): As I said, please feel free to create another ticket for Markdown support. I'm closing this ticket. Thank you for using ntfy :+1:
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
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
starred/ntfy#210
No description provided.