News for hackers. Stuff that matters.
Re:Show HN: Make Your PDF Look Scanned by ArneVogel on Tuesday May 12, 2020 @03:19PM (#23158449)
Edit: fixed now.

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.

Re:Show HN: Make Your PDF Look Scanned by lewiscollard on Tuesday May 12, 2020 @03:57PM (#23158928)
It's still far short of being suitable for use of any private documents.

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).

Re:Show HN: Make Your PDF Look Scanned by baicunko on Tuesday May 12, 2020 @04:11PM (#23159083)
Thank you for the comments. I agree with you, I will decrease how long the file is in the server (I just hit 40gb from hacker news) as well as implement rate limiting to prevent any brute force
Re:Show HN: Make Your PDF Look Scanned by lewiscollard on Tuesday May 12, 2020 @04:31PM (#23159318)
Rate limiting (if by that you mean at the firewall or the web server) is not the way to do it. That shifts the problem somewhere else in the stack, into a place that isn't under version control in the same repository.

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 :)

Re:Show HN: Make Your PDF Look Scanned by bwindsor on Tuesday May 12, 2020 @05:13PM (#23159928)
Re:Show HN: Make Your PDF Look Scanned by lewiscollard on Tuesday May 12, 2020 @07:08PM (#23161213)
Hey thanks - somehow, I entirely missed this being a Thing in the stdlib in 3. :) I've used it in my PR on baicunko's repo.
Re:Show HN: Make Your PDF Look Scanned by mahathu on Wednesday May 13, 2020 @09:45AM (#23166819)
I know this doesn't really add much to the discussion, I just wanted to let you know I really, really appreciate HN over other sites for comments like this. Ones that help you learn something new in a really intuitive and on top of that "non-condescending" way (for lack of a better word I can think of). Thank you!
Re:Show HN: Make Your PDF Look Scanned by lewiscollard on Wednesday May 13, 2020 @06:41PM (#23172685)
Hey, I know I was not as positive & encouraging as I should have been initially, hence the edit on the end. But thank you for the kind words mate, that actually means a lot to me. <3
Re:Show HN: Make Your PDF Look Scanned by baicunko on Tuesday May 12, 2020 @05:41PM (#23160257)
thanks! took me quite a while to prepare as I read a bunch of other servers failing catastrophically when posting on HN due to the sheer amount of traffic.

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

Re:Show HN: Make Your PDF Look Scanned by lewiscollard on Tuesday May 12, 2020 @06:12PM (#23160653)
It was while reading my above comments that I realised I should have shut up and contributed code instead, because that's definitely more helpful than being critical on HN, especially to a newcomer & their first project.

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. :)

Re:Show HN: Make Your PDF Look Scanned by baicunko on Wednesday May 13, 2020 @02:29AM (#23164079)
No worries I think it's great that everyone is voicing their comments. Also, thanks for the PR, will check them later once everything is more normal!
Re:Show HN: Make Your PDF Look Scanned by OriginalPenguin on Tuesday May 12, 2020 @04:41PM (#23159460)
Or use a uuid4 for the suffix.
Re:Show HN: Make Your PDF Look Scanned by tinix on Wednesday May 13, 2020 @12:52AM (#23163590)
https://docs.python.org/3/library/tempfile.html

  >>> 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')
Re:Show HN: Make Your PDF Look Scanned by amhokies on Tuesday May 12, 2020 @04:56PM (#23159693)
You probably shouldn't be uploading sensitive pdfs regardless.
Re:Show HN: Make Your PDF Look Scanned by baicunko on Tuesday May 12, 2020 @03:24PM (#23158511)
Fixed. Sorry, forgot to configure nginx.
Re:Show HN: Make Your PDF Look Scanned by thebigshane on Tuesday May 12, 2020 @03:34PM (#23158638)
Re:Show HN: Make Your PDF Look Scanned by baicunko on Tuesday May 12, 2020 @03:48PM (#23158817)
I manually modified the private key on the server before publishing here. Still learning on ENV VARIABLES and I couldn't make them work!
Re:Show HN: Make Your PDF Look Scanned by 411111111111111 on Tuesday May 12, 2020 @04:26PM (#23159248)
You might want to just switch to a dotenv library. Quick Google for Django yielded https://github.com/jpadilla/django-dotenv
Re:Show HN: Make Your PDF Look Scanned by capableweb on Tuesday May 12, 2020 @05:02PM (#23159794)
Dotenv libraries are just for dev and other similar environments. In production you should still use normal environment variables (or whatever system you use to load your configuration), as dotenv files stay on the filesystem and sometimes even committed to your SCM.
Re:Show HN: Make Your PDF Look Scanned by vmception on Tuesday May 12, 2020 @04:24PM (#23159234)
haha this is like those domain name search websites that just automatically register the good sounding domain names for themselves once the user types it in.

do you OP! I think it still provides a service, enjoy all the secrets

Re:Show HN: Make Your PDF Look Scanned by kchr on Wednesday May 13, 2020 @12:42PM (#23168748)
If you upload secrets to public sites you're in trouble regardless of whether they claim "secure" hosting or not...

And what makes you think the operator has nefarious intent?

Re:Show HN: Make Your PDF Look Scanned by rozab on Tuesday May 12, 2020 @03:41PM (#23158736)
I thought github had hooks for this kind of thing now? I remember it caught a private key I tried to push to a similar django repo (not for a prod site or anything), and that was about 2 years ago
Re:Show HN: Make Your PDF Look Scanned by dewey on Tuesday May 12, 2020 @04:50PM (#23159587)
I think this only works for secret keys that have a certain pattern like AWS keys.