nosdav / server

NosDAV Server
https://nosdav.com/server
MIT License
9 stars 1 forks source link

Crashes when no Authorization header is available #9

Open pablof7z opened 1 year ago

pablof7z commented 1 year ago
file:///home/pablo/nosdav/server/index.js:161
  const nostr = headers.authorization.replace('Nostr ', '')
                                      ^

TypeError: Cannot read properties of undefined (reading 'replace')
    at handlePut (file:///home/pablo/nosdav/server/index.js:161:39)
    at Server.handleRequest (file:///home/pablo/nosdav/server/index.js:33:7)
    at Server.emit (node:events:513:28)
    at parserOnIncoming (node:_http_server:1065:12)
    at HTTPParser.parserOnHeadersComplete (node:_http_common:117:17)

Node.js v18.13.0
melvincarvalho commented 1 year ago

Thanks for the report, I'll look at this probably later today, just finishing the profile proof of concept.

melvincarvalho commented 1 year ago

I've changed

  const nostr = headers.authorization.replace('Nostr ', '')

to

  const nostr = headers?.authorization?.replace('Nostr ', '')
  console.log('nostr auth header', nostr)

in handlePut

This should prevent the crash.