jcoglan / restore

Simple remoteStorage server written in Node.js
293 stars 27 forks source link

500 internal server error when sending malformed `If-Match` #38

Open untitaker opened 8 years ago

untitaker commented 8 years ago

When sending a PUT-request with a header like If-Match: "lolnope", reStore will return a 500 internal server error. The stacktrace acquired with #25 is:

  TypeError: Cannot read property '0' of null
    at Storage.getVersion (/home/untitaker/projects/restore/lib/controllers/storage.js:144:52)
    at null.put (/home/untitaker/projects/restore/lib/controllers/storage.js:69:22)
    at Restore.dispatch (/home/untitaker/projects/restore/lib/restore.js:139:46)
    at IncomingMessage.<anonymous> (/home/untitaker/projects/restore/lib/restore.js:82:10)
    at emitNone (events.js:67:13)
    at IncomingMessage.emit (events.js:166:7)
    at endReadableNT (_stream_readable.js:893:12)
    at doNTCallback2 (node.js:429:9)
    at process._tickDomainCallback (node.js:384:17)

I think the best solution is to refactor reStore to compute the full etag value for the target file, and compare etags/versions as strings instead of integers. That would take care of this problem in a way that doesn't require special handling for parsing errors.