Original: Please don't upload any private or confidential pdfs right now. I emailed OP two security concerns that trivially allow anybody to see any of the converted pdfs.
Original: Please don't upload any private or confidential pdfs right now. I emailed OP two security concerns that trivially allow anybody to see any of the converted pdfs.
https://github.com/baicunko/scanyourpdf/blob/master/pdfwebsi...
This is rather less than secure; output files are named, e.g., "Scan_2020512_{four random lower-case letters}.pdf" into a web-server-readable directory.
That gives a total of 456976 different possible filenames on a day. It's more than feasible to brute-force that many filenames in the hour before files get deleted.
OP: I don't think randomly-suffixed file names are an inherently bad way to approach this. But you should definitely consider using a longer random string, and definitely consider not using the `random` module too (it is not secure and is not intended to be).
Consider: If you moved this on to another server, would you remember to enable rate limiting there? If someone else uses your code, will they know to enable rate limiting?
Rate limiting isn't a bad idea, but your security should not depend on it, especially as you have a way of securing it in your application. base64.b16encode(os.urandom(8)) will give you a 64-bit, filename-safe, as-close-to-random-as-reasonable suffix that should be long enough to make it brute-force-proof :)
The same reasoning applies to the cron job (I presume) that is cleaning your files - that's something you have to remember to set up for future (re-)deployments.
Edit: I'd also like to add that showing your code on HN takes bravery and this is, in fact, a neat tool that solves a problem I really wish didn't exist. So, good work on both counts :)
I will start working on your comments throughout the weekend, I agree with most of them. Would love for you to follow the github page for any other comments you may have, all are appreciated
So that is what I've decided to do! First step: a PR coming out of getting this up and running on my Ubuntu box. :)
>>> tempfile.mkstemp(suffix='.pdf')
(4, '/tmp/tmp0g7l3uq7.pdf')
one could take it a step further... >>> tempfile.mkstemp(suffix='.pdf', prefix=uuid.uuid4().hex)
(5, '/tmp/7b7881400a2348bfae63d37b970d4489pqhz_1g2.pdf')do you OP! I think it still provides a service, enjoy all the secrets
And what makes you think the operator has nefarious intent?