I can't figure out why anyone would need to detect the file type at all. Surely there should be some way for that to be passed into cups (and forwarded on, as necessary) out of band, by the program that created or opened the file and knows what its type is.
Why would a tool that runs any program sent to it on a device it doesn’t know about be that concerned about being sent an invalid program?
An attacker might send a file that orders for millions of dollars of pizzas, using the fax hardware built into the printer (I’m not sure you can buy postscript printers that can fax today, but you can buy printers that can fax even today)
I'm having trouble understanding your question in the context of the discussion, so I will talk about the topic generally instead.
Imagine a server allows you to upload images. It has a system designed for images only. It will behave unpredictably maybe even dangerously with another file. The server checks that the file ends with .jpg. it checks that the file is a valid jpeg. All clear. Upload allowed. But 5 steps later some tool looks at the image file and notices it's a valid zip file (creating files with multiple valid interpretations is something people have succeeded in doing it's not always so hard). It runs this check before the image check. The next step in the processing chain wants an image but it has been told it's dealing with a zip file. So it unzips the file to see if it contains an image. But it was a zip bomb. The server goes down.
If the printer endpoint of the USB device receives a file that orders millions of pizzas, it will print the file (or print a PS error, or print the plaintext contents of the file), not order pizzas.
If the user mistakenly "prints" to the fax device, the file will be printed at the destination fax machine, at the number the user typed, not the number in the file, and it will print, not order pizzas (unless the pizzeria accepts fax orders, which would be a prank, not an attack).
“FaxOptions Dictionary This dictionary contains parameters that direct fax transmissions from a PostScript language program. Refer to “Fax Parameters” on page 29 for further information about FaxOptions defaults and the keys found in this dictionary”
Google tells me this is what you needed in your PostScript file to send a fax:
I'm still not sure PS can fax. Specs looks more like page formatting for faxing devices. Anyway, I learn something new every day!
But even if it is capable, currently used cups validation would still find a valid PS even if the PS contents itself is malicious.
What you need is a printer that decides what to do with a file based on file contents instead of instructions from the computer. Like, "Computer: Print this as an unformatted text file!" / "Printer: This text fine you sent me is actually a PS file. I'm going to fax it instead, because it says so inside."
CUPS depends on, and is a dependency for, half the OS for some reason. At least under Ubuntu, if you've got a machine you're planning to decommission, try:
`sudo apt purge libcups*`
NB, don't do this on a system you're planning to keep operational, this will autoremove half the OS if allowed to run.