Security of uploading and parsing Named Binary Tag files (NBT) via PHP

275 Views Asked by At

I'm building a application that deals with uploading/downloading Named Binary Tag files (NBT).

After they're uploaded I need to parse them and get some information.

I'm a bit concerned security wise as I don't have the necessary knowledge to properly understand how they're build or what kind of data to expect from them.

  • What are some sanity checks that I can perform, when the files are uploaded, to make sure that they are indeed NBT files.

  • Should I be concerned when parsing them?

  • If there's anything else I should be concerned with, please, do tell.

I realize these are vague questions. There aren't a lot of answers on Google, else I wouldn't be here.

1

There are 1 best solutions below

0
On BEST ANSWER

The file-format for NBT is really simple and compact. It's a binary stream (uncompressed or gzipped), which was specified by Notch.

One "problem" comes with special crafted NBT-files, which contains a lot of empty lists and lists of lists ... the memory-overhead of parsing these may result in service failure (mostly because the created objects for each entry just fills your memory).

One solution could be to limit the amount of entries you are reading and when reaching that limit just dropping the parsed file.

I recently published a java-library for reading nbt-files (but without having a limit), maybe it helps you to understand that file-format.

edit: forgot to share this website about the "exploit": http://arstechnica.com/security/2015/04/just-released-minecraft-exploit-makes-it-easy-to-crash-game-servers/