Skip to content
This repository has been archived by the owner on Jul 15, 2023. It is now read-only.

Insecure use of temporary file #1905

Closed
antong opened this issue Sep 2, 2018 · 5 comments · Fixed by #1912
Closed

Insecure use of temporary file #1905

antong opened this issue Sep 2, 2018 · 5 comments · Fixed by #1912

Comments

@antong
Copy link

antong commented Sep 2, 2018

There are multiple insecure uses of temporary files in the vscode-go extension. I found the following just looking at the output console:

On a multi-user or shared system such clashing or predictable use of temporary files is a hassle at best (two users cannot use vscode without errors) to a serious security issue at worst.

For example, on some system configurations user Bob can overwrite arbitrary files belonging to user Alice (or root) using a symlink attack:

bob@box$ ln -s /home/alice/thesis.tex /tmp/go-code-cover
bob@box$ ln -s /etc/passwd /tmp/vscode-go-debug.txt 

(This example is prevented on modern Linux systems if /tmp has the sticky bit set.)

Recommendation: use secure library functions for temporary files and private files (e.g., in the home directory or workspace) for non-temporary files.

@ramya-rao-a
Copy link
Contributor

use secure library functions for temporary files

Can you elaborate on this?

@antong
Copy link
Author

antong commented Sep 2, 2018

Because of the pitfalls in using temporary files, most systems include ready functions to securely create temporary files. POSIX has a family of functions like mkstemp(), mkdtemp(), ... Go has ioutil.TempFile() and ioutil.TempDir(). Python has a tempfile module. I'm not sure about Javascript, but googling found fs.mkdtemp() in Node.js.

By the way, thank you @ramya-rao-a for all your work on vscode-go! It is really appreciated.

@ramya-rao-a
Copy link
Contributor

Thanks for the links!

PRs are welcome to fix this.
Code pointers:

  • Read Build and Debug Go extension for local setup of the extension
  • As mentioned above fs.mkdtemp can be used to create a unique temp directory under the os.tmpdir()
  • The above should be done once and the value should be stored in local storage for future use.
  • util.ts would be the right place to add a function to get this tmp dir

@0xch4z
Copy link
Contributor

0xch4z commented Sep 3, 2018

I'll take this!

@ramya-rao-a
Copy link
Contributor

The fix for this is now out in the latest update to this extension (0.6.90)

@vscodebot vscodebot bot locked and limited conversation to collaborators Oct 28, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants