BobbyWibowo / lolisafe

Blazing fast file uploader and awesome bunker written in node! 🚀
MIT License
317 stars 56 forks source link

Chunked uploads fail when coming from IPv6 addresses #647

Closed flleeppyy closed 1 year ago

flleeppyy commented 1 year ago
[2023-04-07 22:50:28] [Error: EINVAL: invalid argument, mkdir 'E:\chensafe uploads\chunks\2600:1008:a000:645d:e024:35d4:7ab2:a1d0_a26bea63-2b
4c-44a2-a03e-00ab1719e2d5'] {
  errno: -4071,
  code: 'EINVAL',
  syscall: 'mkdir',
  path: 'E:\\chensafe uploads\\chunks\\2600:1008:a000:645d:e024:35d4:7ab2:a1d0_a26bea63-2b4c-44a2-a03e-00ab1719e2d5'
}

My safe is routed through CloudFlare, and they've recently forced IPv6 to be turned on, so uploads from IPv6 addresses have failed, and IPv6 addresses include colons which are illegal characters in filenames.

I've never deeply looked at the codebase for lolisafe, but we can probably create a temporary variable that acts as a cachemap(?) https://github.com/BobbyWibowo/lolisafe/blob/cf38c8ac50f006e98df9775500ec121bed888989/controllers/uploadController.js#L375

i.e

// This is declared somewhere in the controller
const cacheMap = {};

// Inside self.actuallyUpload
const idForCache = crypto.randomUUID().split("-")[0];
cacheMap[idForCache] = req.ip
const uuid = `${idForCache}_${req.body.uuid}`

This probably isn't practical, and I don't know what I'm doing.

BobbyWibowo commented 1 year ago

I'm thinking of just normalizing the semicolons : into dashes - Generating UUIDs for the IPs seem redundant, since the IPs themselves already serve as unique identifications

Internally, we separate IPs from the files' UUIDs via the underscore symbol _ alone, so there should be no conflict there Or in fact, I don't recall the codes actually having to re-parse the directory path, because IP + file's UUID as a whole is already the only identification needed until the file's chunked uploads have all been finalized (meaning, the client reports to server that all chunks have been uploaded, and should then be finalized)

I'll push a commit with said change in a bit, feel free to test it more thoroughly then

BobbyWibowo commented 1 year ago

Should be okay with commit https://github.com/BobbyWibowo/lolisafe/commit/2a8901a903952f3f8712443a5ab4abbffdbdcb21 Feel free to comment if there's anything else