Live data from Hacker News

Show HN: PDF Inverter for macOS (In Golang) Darken Your PDFs

github.com

21–30 of 38 posts

Re: Show HN: PDF Inverter for macOS (In Golang) Darken Your PDFs

#21
post #7

https://github.com/rootVIII/pdfinverter/blob/master/utils.go... using go to wrap a python script - this is some "hacker man" stuff right here

And written to be less readable with e.g.:

    return bytes.ReplaceAll(script, []byte{0x09}, []byte{0x20, 0x20, 0x20, 0x20})
instead of

    bytes.ReplaceAll(script, []byte("\t"), []byte("    "))
Skimming through the code, there's a lot of other pretty basic mistakes.

The most egregious is that the use of a python script has a security issue. Let's see if you can spot it, it's in these lines:

    tmp := fmt.Sprintf("/var/tmp/invertpdf--%s/", time.Now().Format("20060102150405"))
    os.Mkdir(tmp, 0700)
    WriteText(tmp+"pngtopdf.py", GetPDFConv())
    // later execute that .py file
So, what's the issue? Well, using a predictable temporary directory and then not checking for an error in `mkdir` means that an attacker can easily create that directory before you do (especially since it's a predictable name based on the time), and then write their own python script. That lets another user on your machine run arbitrary code as your user.

"But", you might say, "WriteText does an os.Exit if it can't write the file". That doesn't matter. If i create the directory with permissions 777, and then have a program waiting for the python script to be written in order to replace it with a malicious script, Mkdir will error (dir already exists), but WriteText will succeed, and so the vulnerability still happens.

This is the sort of dumb vulnerability you get if you don't know that `ioutil.TempDir` exists (or don't know about symlink races, tmpdir races, etc). `ioutil.TempDir("/var/tmp", "invertpdf-")` would be the more secure way to do this, though obviously you still should check that error too.

There's a lot of other problems with this program, but this vulnerability is the most obvious.

Re: Show HN: PDF Inverter for macOS (In Golang) Darken Your PDFs

#23
post #2

A browser plugin that I use for Safari/Chrome/Firefox/Edge does this too ( https://darkreader.org ). > Configure the dark theme: brightness, contrast and sepia. Enable for all websites or particular domains. Works for PDFs too. No affiliation.

I like dark reader too, with the most gpu intensive mode and sepia it makes for some really good dark modes for most websites. And I’ve built dark mode css off of it as an inspiration.

Edit: the "Dynamic" (GPU) mode doesn't work on all sites. On HN I'll use Filter+ with the settings -20 brightness, contrast off, sepia +30, grayscale off.

While on Github I'll do -5, 0, +30, 0. Mainly just tweaking the brightness while having Sepia on most sites.

Re: Show HN: PDF Inverter for macOS (In Golang) Darken Your PDFs

#24
post #15
post #4

You can do this on-the-fly with Zathura... in Linux

You can also do it in Okular.

Also GNOME's default PDF reader. Don't know what it's called though.

Edit: It appears to be Evince [0]

[0] https://en.wikipedia.org/wiki/Evince

Re: Show HN: PDF Inverter for macOS (In Golang) Darken Your PDFs

#25
post #7

https://github.com/rootVIII/pdfinverter/blob/master/utils.go... using go to wrap a python script - this is some "hacker man" stuff right here

It may be possible to replace the dependency on the python script by using objective c to call the required libraries, then expose a c API that can be called from the go application. E.g. https://gist.github.com/porty/6b94f7f908ed7af0f070 https://github.com/caseymrm/menuet

That said, I've seen messier things than python-in-go shipped and used reliably in production to solve business problems.

Re: Show HN: PDF Inverter for macOS (In Golang) Darken Your PDFs

#27
post #2

A browser plugin that I use for Safari/Chrome/Firefox/Edge does this too ( https://darkreader.org ). > Configure the dark theme: brightness, contrast and sepia. Enable for all websites or particular domains. Works for PDFs too. No affiliation.

I like dark reader too, with the most gpu intensive mode and sepia it makes for some really good dark modes for most websites. And I’ve built dark mode css off of it as an inspiration. Edit: the "Dynamic" (GPU) mode doesn't work on all sites. On HN I'll use Filter+ with the settings -20 brightness, contrast off, sepia +30, grayscale off. While on Github I'll do -5, 0, +30, 0. Mainly just tweaking the brightness while…

[deleted]

Re: Show HN: PDF Inverter for macOS (In Golang) Darken Your PDFs

#29
post #25
post #7

https://github.com/rootVIII/pdfinverter/blob/master/utils.go... using go to wrap a python script - this is some "hacker man" stuff right here

It may be possible to replace the dependency on the python script by using objective c to call the required libraries, then expose a c API that can be called from the go application. E.g. https://gist.github.com/porty/6b94f7f908ed7af0f070 https://github.com/caseymrm/menuet That said, I've seen messier things than python-in-go shipped and used reliably in production to solve business problems.

That or just write the whole script in Python and avoid a needless Go dependency.

Re: Show HN: PDF Inverter for macOS (In Golang) Darken Your PDFs

#30
post #21
post #7

https://github.com/rootVIII/pdfinverter/blob/master/utils.go... using go to wrap a python script - this is some "hacker man" stuff right here

And written to be less readable with e.g.: return bytes.ReplaceAll(script, []byte{0x09}, []byte{0x20, 0x20, 0x20, 0x20}) instead of bytes.ReplaceAll(script, []byte("\t"), []byte(" ")) Skimming through the code, there's a lot of other pretty basic mistakes. The most egregious is that the use of a python script has a security issue. Let's see if you can spot it, it's in these lines: tmp := fmt.Sprintf("/var/tmp/invertp…

Thanks for the feedback. Yeah the Python part is definitely a bit hackish. Do you have any other recommendations on other problems? I'm still learning Golang and would like to improve. Thanks!
Post reply on HN