Repository navigation
What's new
This release closes several upload and download security holes, fixes the client upload state machine, and supports Meteor 3.2 to 3.5. Read "Major changes" before you upgrade. See the new security guide.
Major changes
⚠️ Require Meteor 3.2 or newer.ostrio:cookies3.0.0 needsfetch@0.1.6, which first ships with Meteor 3.2.⚠️ Restart uploads that were in progress during the upgrade from 3.0.x. The server answers403or410for upload records created by 3.0.x.⚠️ Return HTTP upload errors as{ error: <status code>, reason, isClientSafe? }instead of{ error: "<text>" }.5xxresponses have a genericreason.⚠️ Limit upload sizes.chunkSizeis at most 16 MiB. HTTP Start bodies, includingmeta, are at most 1 MiB. HTTP EOF bodies are at most 64 KiB. HTTP chunk bodies are at most the Base64 size ofchunkSizeplus 4 KiB.⚠️ RejectFileUploadpipes that grow a chunk. A pipe must return Base64 that decodes to the same number of bytes as its input, so per-chunk encryption with an IV, a tag, or padding fails on the first chunk. Move such transforms toonAfterUploadon the server.⚠️ Emit onlyerrorandendwhen an upload fails.pause,abort, andonAbortnow fire only whenabort()is called.⚠️ ThrowMeteor.Error 404from the synchronousFilesCursormethods (get,fetch,first,last,next,previous,hasNext,count,forEach,each,map,current,remove) and fromFileCursor#with()andFileCursor#remove()on the server. They returned Promises or wrong values before. Use the*Asyncmethods.⚠️ RejectwriteAsync()andloadAsync()with409whenopts.fileIdalready exists. Before, they overwrote the existing file.⚠️ Reject an upload Start withfile.size0with400. An empty upload has no chunk to send and never finished. The client already refused empty files.⚠️ Stop retrying a chunk after 10 consecutive network failures and end the upload with an error. Before, the client retried without limit.
Other Changes
Fixed
- 🔧 Accept Write, EOF, and abort requests only from the user who started the upload.
- 🔧 Stop
_Abortfrom removing finished files. It removes only the unfinished upload record and its partial file, and answers404for unknown or foreign upload ids. - 🔧 Remove the partial file when an upload is aborted after a server restart. The server removes it only when device, inode, and birth time match the file the upload created. Without a stored birth time (file systems that do not report it), device and inode must match.
- 🔧 Prevent an upload from overwriting or deleting another file. Start returns
409if the file id, the target path, or a pending upload path already exists, and creates the file exclusively. - 🔧 Fail an upload with
410or409when its file was removed or replaced on disk. The server compares device, inode, and birth time on every reopen. - 🔧 Sanitize
namingFunctionoutput per path segment and require the final path to stay insidestoragePath. - 🔧 Ignore client-supplied reserved file fields:
_id,fileId,path,_storagePath,_downloadRoute,_collectionName,versions,userId,public, extension, mime, and type flags. - 🔧 Store the real size on disk, and reject chunks beyond the declared size.
- 🔧 Validate chunk size, chunk count,
chunkId, and chunk length. - 🔧 Reject oversized HTTP request bodies with
413before buffering them. - 🔧 Run the same
check()on HTTP Start as on DDP Start. - 🔧 Stop sending server paths to the client in Start and EOF responses.
- 🔧 Destroy download streams when the client disconnects. Stream errors return a generic
500. - 🔧 Match routes by URL pathname, so a query string or a route prefix can no longer match another route.
- 🔧 Encode
Content-Dispositionwith an ASCIIfilenameand an RFC 8187filename*. The ASCII fallback replaces%with_. - 🔧 URI-encode
_id, version, extension, and collection name inlink()and thefileURLhelper, and never produce protocol-relative URLs. - 🔧 Return an empty string from
link()and thefileURLhelper for a file without_id, for example the file passed toendafter a rejected upload. It returned/undefined/original/undefined.txtbefore. - 🔧 Set the
x_mtokcookie assecureon https pages. - 🔧 Ignore inherited keys in the session lookup and fail closed.
- 🔧 Skip
__proto__,constructor, andprototypeinfixJSONParseandfixJSONStringify. - 🔧 Limit a numeric
protectedresult to400-599. - 🔧 Return the stored file on a repeated EOF only to the authenticated owner, so a lost EOF response no longer fails a finished upload.
- 🔧 Answer an EOF that arrives while the first EOF of the same upload is still running (for example after a DDP reconnect) with the result of the first one instead of
408. - 🔧 Accept an object in
responseHeaders. - 🔧 Serve suffix ranges (
bytes=-N) and the last byte, clamp the range end to the file size, and return200for multi-range requests. Unsatisfiable ranges return416whenstrictistrueand200when it isfalse. - 🔧 Send
Content-Lengthon206responses thatserve()reads from disk, instead ofTransfer-Encoding: chunked. A response never carries both headers. - 🔧 Send
206responses from a customreadableStreamchunked, withoutContent-Length, becauseserve()can not know how many bytes the stream sends. AContent-Lengthset inresponseHeadersis kept. A200still getsContent-Lengthfrom the stored size, as in 3.0. - 🔧 Give up a Start or EOF request, or a chunk answered with
502,503, or504, after 5 failed attempts, as documented. Before, it took 6. - 🔧 Make the integrity-check
400response reachable again. - 🔧 Stop
loadAsync()from throwing inside a timer. It opens the file only after a successful fetch, takessizefrom disk, and removes only partial files it created. - 🔧 Make
writeAsync()create the directory and always close the file handle. - 🔧 Complete an upload when all chunk ids arrived instead of guessing from the file size. Uploads resume after a server restart.
- 🔧 Return
503when a chunk write fails. - 🔧 Make
WriteStream#end()returnfalsefor aborted or incomplete streams, and stopabort()from deleting a finished file. - 🔧 Remove the uploaded file when the database insert fails, and rethrow insert errors.
- 🔧 Run
namingFunctionandstoragePathonce per upload, at Start. - 🔧 Run
onInitiateUploadafter the server checked that the target does not exist. - 🔧 Find public route ids that contain
-. - 🔧 Set
extensionWithDotto an empty string for files without extension. - 🔧 Treat a
responseHeadersfunction that returns nothing as{}. - 🔧 Catch version unlink failures and log index creation errors.
- 🔧 Treat a file that is already gone as removed in
unlinkAsync()andremoveAsync(). The server logs one debug line without a stack trace. - 🔧 Send one client request at a time: Start, chunks in order, then EOF. Network failures,
502,503, and504retry with backoff from 500 ms up to 10 s. - 🔧 Prevent the client from sending a chunk before Start succeeds, and fire
endanduploadedonly after a successful EOF. - 🔧 Send Start when
continue()follows a pause before Start. - 🔧 Stop
abort()from causing an unhandled rejection when the server answers404. - 🔧 Pass the
reasonof HTTP4xxresponses toerror,onError, andend. - 🔧 Call
errorandendonce per failed upload. A throwing callback is reported withconsole.errorand does not stop the others. - 🔧 Keep a manual pause when the connection drops and comes back.
- 🔧 Omit the
x-mtokheader when there is no session instead of sending the string"null". - 🔧 Fix Base64 padding for chunk sizes not divisible by 4.
- 🔧 Stop
insert()andinsertAsync()from changing the config object passed by the user. - 🔧 Keep
metaDates as Dates after an HTTP upload. - 🔧 Start the worker, the
beforeunloadlistener, timers, and trackers only afteronBeforeUploadpasses, and always clean them up. - 🔧 Post worker errors to the main thread and share one Blob URL between collections.
- 🔧 Stop the client constructor from crashing on
new FilesCollection(). - 🔧 Update the
x_mtokcookie after reconnect and login without overwriting the app'sonReconnecthook. - 🔧 Reject client
removeAsync()with401whenallowClientCodeisfalse. - 🔧 Accept
null,undefined, andFileCursorinlink(). - 🔧 Accept the same selectors in
countDocuments()as infind(), including ObjectID. - 🔧 Honor
limitandskipinhasNextAsync()andlastAsync(). - 🔧 Stop
estimatedDocumentCount()from failing in debug mode. - 🔧 Fix typos in JSDoc and error messages.
- 🔧 Match
index.d.tsto the runtime API. Many options and method signatures were missing or wrong. - 🔧 Keep uploads, downloads, and writes running when a custom
debugfunction throws. The error goes to the console. - 🔧 Throw from
_dataToSchema()whenstoragePathresolves to a Promise that was not awaited, so a Promise never lands in a stored document.
Added
- ✨ Add the
allowedCordovaOriginsoption on Server and Client, passed toostrio:cookies. Cordova and Meteor-Desktop need it for query-string cookies. The Server default is the value ofallowedOrigins. - ✨ Add the
uploadIdleTimeoutServer option (milliseconds, default900000). It closes file handles of idle uploads, and the next chunk reopens them. - ✨ Add the
nosniffServer option. It setsX-Content-Type-Options: nosniff(defaultfalse, planned to default totruein v4). - ✨ Warn on server start when
allowClientCodeis on andonBeforeRemoveis not set. - ✨ Add
userAsync()to the client_getUser()result. - ✨ Allow the
debugoption to be a function. The server and client pass log arguments to it instead of the console. Thanks to @jankapunkt, #907. - ✨ Allow the
storagePathfunction to beasync.collection.storagePath(fileObj)returns a Promise in this case, soawaitit. Thanks to @codeonprod, #909.
Changed
- 👨💻 Use the stored
_downloadRouteand_collectionNameinlink()when they are safe, otherwise the collection's own values. A stored route with?,#, or an encoded.,/, or\(%2e,%2f,%5c) is not safe. - 👨💻 Answer
?play=truerequests without aRangeheader with200and the whole file, as RFC 9110 requires. Requests withRangestill get206. - 👨💻 Add
; charset=utf-8to the defaultContent-Typeoftext/*,application/json,application/javascript, andimage/svg+xmlfiles without a charset, so text files display correctly inline. Text files in another encoding, such as a Latin-1 CSV, need their charset set throughresponseHeaders. - 👨💻 Ask the user to check the connection when one chunk fails 10 times in a row, and name a chunk larger than
chunkSize(for example from a pipe) as one possible cause. - 👨💻 Export types from
index.d.tsat the top level. The olddeclare modulewrapper exported nothing. - 👨💻 Keep
FileUploadpipes in reverse order of registration. This changes in v4. - 🤫 Ignore
docs/audits/in git.
Docs
- 📔 Add a security guide.
- 📔 Rename the migration doc to
migration-to-v3.md. - 📔 Rewrite the AWS S3 (
@aws-sdk/client-s3v3), Dropbox, Google Cloud Storage, GridFS, andsharpthumbnail guides with async APIs and correct Range handling. - 📔 Document
updateAsync,countDocuments,estimatedDocumentCount,serve,download,allow/deny, the exported helpers, and theprogressevent arguments. - 📔 Document upload rules, limits, and the HTTP error body in
about-transports.md. - 📔 Document the event order:
abort()emitspause, thenabort, and noend. A failed upload emitserror, thenend. Document thatabort()does not cancel an EOF or HTTP Start request that is already sent. - 📔 Document that a custom
readableStreampassed toserve()for aRangerequest should contain exactly the requested bytes, and whenserve()setsContent-Length. - 📔 Fix wrong defaults, broken links, typos, and samples that did not run on Meteor 3.
- 📔 Add
CLAUDE.mdwith commands, architecture notes, and invariants for contributors and coding agents. - 📔 Update the README, the docs index, and
CONTRIBUTING.md: Meteor 3.2 requirement, links to the security and migration guides, andIsomorphicinstead ofAnywherein API labels. - 📔 Document the
debugfunction and the asyncstoragePathoption indocs/constructor.md, andawaitstoragePath()in thesharpthumbnail guide.
Tests
- 🧪 Add
tests/security.test.jsfor upload ownership, path safety, request limits, Range parsing, and access checks. - 🧪 Port Tinytest helpers to mocha and fix tests that passed without asserting.
- 🧪 Cover
Content-Lengthon200and206for files and custom streams,HEAD,?play=true, default charsets, racing EOFs (also anonymous), abort after restart (also for records without file identity),link()without_id, encoded routes, and unlink of missing files. - 🧪 Check types with
tscandtsd(npm run typecheck). - 🧪 Cover the
debugfunction option and asyncstoragePath(Promise return, rejection, startup,writeAsync,loadAsync). - 🏗️ Run lint, typecheck, and tests in CI on Meteor 3.2.2 and 3.5.2.
- 🏗️ Replace
.eslintrcwith an ESLint 9 flat config, without the deprecatedno-extra-semiandno-native-reassignrules.
Dependencies
- 📦
ostrio:cookies3.0.0 - 📦
eventemitter35.0.4 - 📦
meteortesting:mocha3.4.0,chai6,sinon22 for tests - 📦 Update the dev dependency lockfile (
js-yaml, ESLint 9, TypeScript 5.9,tsd) and the packagenpm-shrinkwrap.json