--- netrc-3.4.0a1.py 2013-09-08 21:48:38.000000000 +0200 +++ netrc.py 2013-09-08 22:23:30.000000000 +0200 @@ -2,7 +2,7 @@ # Module and documentation by Eric S. Raymond, 21 Dec 1998 -import io, os, shlex +import io, os, stat, shlex __all__ = ["netrc", "NetrcParseError"] @@ -29,6 +29,13 @@ self.hosts = {} self.macros = {} with open(file) as fp: + prop = os.fstat(fp.fileno()) + if os.name == 'posix': + if prop.st_uid != os.getuid(): + raise OSError( + ".netrc file owned by somebody else (%d)" % prop.st_uid) + if (prop.st_mode & (stat.S_IRWXG | stat.S_IRWXO)): + raise OSError(".netrc file : incorrect mode") self._parse(file, fp) def _parse(self, file, fp):