Cyber Risks · Trail of Bits Blog

Smart (and simple) ways to prevent symlink attacks in Go

Summary: Trail of Bits describes how Go's os.Create returns a nil error even when it truncates an existing file, so a symlink placed at the target path causes the program to wipe the linked file's contents without any error. The fix is an os.IsNotExist check before creation, or opening with O_NOFOLLOW or writing to a temp file and renaming it, to close the time-of-check versus time-of-use gap.

What you should know: An attacker can point a symlink at audit logs that would reveal their presence on the box, and the program will erase them for the attacker while reporting success.

Read the original at Trail of Bits Blog ↗