ntfy icon indicating copy to clipboard operation
ntfy copied to clipboard

default-user and default-password in client.yml not working

Open pinpox opened this issue 1 year ago • 3 comments

I've created a file in ~/.config/ntfy/client.yml with this content

default-host: https://push.pablo.tools
default-user: pinpox
default-password: mysupersecretspassword

But the client seems to ingnore the values:

$ ntfy pub --config ~/.config/ntfy/client.yml https://push.pablo.tools/test                                                                                                                                                         
{"code":40301,"http":403,"error":"forbidden","link":"https://ntfy.sh/docs/publish/#authentication"}

Using the NTFY_USER environment variable works, so I know the crendentials are in fact correct:

$ export NTFY_USER=pinpox:mysupersecretspassword
$ ntfy pub test test                                                                                                                                                                                                                
{"id":"ix6JqNqNDETe","time":1667306079,"event":"message","topic":"test","message":"test"}

pinpox avatar Nov 01 '22 12:11 pinpox

So I looked at the code and it should work. I'll try this out. :thinking:

binwiederhier avatar Nov 02 '22 18:11 binwiederhier

Note that this leaks/publishes notifications send to a private instance with the 'ntfy cli', to the public instance at https://ntfy.sh/*, because the configured default-host is ignored.

notDavid avatar Nov 10 '22 10:11 notDavid

Note that this leaks/publishes notifications send to a private instance with the 'ntfy cli', to the public instance at https://ntfy.sh/*, because the configured default-host is ignored.

My evil plan to collect user passwords is working :smiling_imp: -- Just kidding. You're right, I should look at this urgently.

binwiederhier avatar Nov 11 '22 13:11 binwiederhier

@notDavid Can you confirm notifications are being leaked? I just tested it locally, and it seems like default-host is being used correctly. I think only default-user and default-password are being ignored

wunter8 avatar Nov 12 '22 17:11 wunter8

I figured out what's going on.

The code to use default-user and default-password for ntfy **sub** was released in version 1.28.0.

But the code to use default-user and default-password for ntfy **pub** hasn't been released yet. It's included in (unreleased) version 1.29.0.

Sorry about the (temporary) inconsistency!

wunter8 avatar Nov 12 '22 18:11 wunter8

As per @wunter8's comment, this was fixed in #431. I'm going to release the code today.

binwiederhier avatar Nov 12 '22 18:11 binwiederhier

Glad you found it :-) I don't fully understand by the way, in particular why the setting default-host does not work either...? But if you say it will be fixed it's fine! 🤗

notDavid avatar Nov 12 '22 18:11 notDavid

For the record, this gets send to ntfy.sh instead of my own server:

~ ❯ cat ~/.config/ntfy/client.yml | grep -i 'default-host'
# default-host: https://ntfy.sh
default-host: https://ntfy.xxxxx.nl

~ ❯ ntfy pub mytopic 221112.1951
{"id":"t4xLhs9odPPO","time":1668279076,"event":"message","topic":"mytopic","message":"221112.1951"}

notDavid avatar Nov 12 '22 18:11 notDavid

Can you confirm what version of ntfy you're using? (ntfy -h | tail -n2)

wunter8 avatar Nov 12 '22 19:11 wunter8

~ ❯ ntfy -h | tail -n2
ntfy 1.28.0 (d3cfa34), runtime go1.18.6, built at 2022-09-27T16:55:57Z
Copyright (C) 2022 Philipp C. Heckel, licensed under Apache License 2.0 & GPLv2

notDavid avatar Nov 12 '22 19:11 notDavid

What happens when you subscribe to a topic? Does it use the configured default-host? (ntfy sub --trace mytopic)

wunter8 avatar Nov 12 '22 19:11 wunter8

❯ ntfy sub --trace mytopic
2022/11/12 20:32:15 DEBUG ntfy.sh/mytopic Subscribing to topic
2022/11/12 20:32:15 DEBUG ntfy.sh/mytopic Listening to https://ntfy.sh/mytopic/json
2022/11/12 20:32:16 TRACE ntfy.sh/mytopic Message received: {"id":"6VVJWtYIBy5a","time":1668281536,"event":"open","topic":"mytopic"}

notDavid avatar Nov 12 '22 19:11 notDavid

Alright. Now let's check file permissions: ls -al ~/.config/ntfy/client.yml

wunter8 avatar Nov 12 '22 19:11 wunter8

❯ ls -al ~/.config/ntfy/client.yml
-rw-r--r--  1 david  staff  1947 Nov 10 11:14 /Users/david/.config/ntfy/client.yml

notDavid avatar Nov 12 '22 19:11 notDavid

Oh, you're on Mac? I think the default path for client.yml on MacOS is ~/Library/Application Support/ntfy/client.yml. So you could either move your config file there, or specify the path to the config file in the command: ntfy sub --trace --config ~/.config/ntfy/client.yml mytopic

wunter8 avatar Nov 12 '22 19:11 wunter8

(I just released the v1.29.0, so you should also try that.)

binwiederhier avatar Nov 12 '22 19:11 binwiederhier

@wunter8 Ahhhh yes that works. Thank you, and sorry for the confusion, i did not realize... 🫣

@binwiederhier Yes, 1.29.9 is working also with the username/password :-)

notDavid avatar Nov 12 '22 20:11 notDavid

@wunter8 fyi, I followed the docs here, which is why i put the config file in that location: https://ntfy.sh/docs/subscribe/cli/#install-configure

Perhaps it's a good idea to update that, might save you some time in the future :-)

notDavid avatar Nov 12 '22 20:11 notDavid

I found the default path for MacOS here: https://ntfy.sh/docs/subscribe/cli/#subscribe-to-multiple-topics

But I agree we should probably update the docs elsewhere

wunter8 avatar Nov 12 '22 20:11 wunter8

@wunter8 By the way, wouldn't it make more sense to change this to ~/.config/ntfy/client.yml, where all other dot files are?

I don't have a single commandline tool which puts their dot files in ~/Library/Application Support/...

notDavid avatar Nov 13 '22 07:11 notDavid