germanoeich / nirn-proxy

Distributed transparent REST proxy for the Discord API, handles ratelimits for you, multi-bot support, dynamic, version agnostic
GNU General Public License v3.0
131 stars 24 forks source link

GET webhooks/:webhookId/:webhookToken/messages/:msgId always returns 404 #19

Open Larsundso opened 3 months ago

Larsundso commented 3 months ago

How to reproduce:

Possible prerequisites

Every time i restarted the docker image it would work for 5-10 seconds before returning 404 again The error description would be "No Description" I encountered this only after releasing a Feature that would utilize several hundred webhooks sending several thousand requests per minute combined

Larsundso commented 3 months ago

I'm not sure what other webhook endpoints are affected, but DELETE webhook message is too

Larsundso commented 3 months ago

Fixed by restarting the docker container Edited issue

Zoddo commented 3 months ago

@Larsundso I think you can reopen the issue because you found a bug.

I can repro reliably by trying to get a message that don't/no longer exists.

Repro steps:

  1. Post a message using a valid webhook: curl -i -X POST -H 'Content-Type: application/json' http://nirn-proxy.prod.svc.cluster.local/api/webhooks/:id/:token?wait=true -d '{"content":"test"}'
  2. Get the message, it should returns a 200: curl -i http://nirn-proxy.prod.svc.cluster.local/api/webhooks/:id/:token/messages/:id
  3. Repeats step 2 with an invalid ID (do +1 in the message ID). You get a {"message": "404: Not Found", "code": 0} as expected.
  4. Repeat step 2 again with the valid message ID. You now get a fake 404 "Unknown webhook" originating from nirn (as it can be seen with the missing CF's headers in the response).

The issue likely lies here: https://github.com/germanoeich/nirn-proxy/blob/23fc2e790b136134283a985c4b779ecc1ba389f4/lib/queue.go#L351-L358

It should additionally check if the body code is 10015 (Unknown webhook).

I looked to make a PR but I'm not sure how to parse the body and I'm not a go dev :(