classification
Title: netrc module allows read of non-secured .netrc file
Type: security Stage:
Components: Library (Lib) Versions: Python 3.3, Python 3.2, Python 2.7, Python 2.6
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: barry, bruno.Piguet, r.david.murray
Priority: high Keywords:

Created on 2012-06-02 12:53 by bruno.Piguet, last changed 2012-06-09 13:58 by r.david.murray.

Files
File name Uploaded Description Edit
patch_netrc_2.6.txt bruno.Piguet, 2012-06-09 09:55 example of what could be a patch against the 2.6 version of netrc.py
Messages (4)
msg162132 - (view) Author: bruno Piguet (bruno.Piguet) Date: 2012-06-02 12:53
Most FTP clients require that the .netrc file be owned by the user and readable/writable by nobody other than the user (ie. permissions set to 0400 or 0600).
The netrc module doesn't do this kind of checking, allowing the use a .netrc file written or modified by somebody else.
msg162165 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2012-06-02 19:02
This seems like something we should fix for the default file read.  There is a backward compatibility concern, but I think the security aspect overrides that.
msg162556 - (view) Author: bruno Piguet (bruno.Piguet) Date: 2012-06-09 09:55
Do you agree that the attached patch could be a practical solution ?
The patch is for the 2.6 version of the lib. Transposition to other versions should be trivial.

If we don't want to break backward compatibility, the solution is to add a optional behavior flag argument,
something like def __init__(self, file=None, sec_mode=False):
and have the default value be False for old versions and True for 3.3 and further.
msg162561 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2012-06-09 13:58
Thanks for the patch.

I think the extra check should be done unconditionally in the case where we've looked up the default .netrc file.  Adding a feature to 3.3 to provide an optional check for other files (with default False) would then be an additional enhancement, and I think a good one.  That should be a separate patch, probably even a separate issue.

I don't think the parse error is the right thing to raise, but I'm not sure what is.  An OSError, perhaps?

I'm adding the 2.6 release manager to see if he thinks this is of sufficient importance to go into a 2.6 release.
History
Date User Action Args
2012-06-09 13:58:40r.david.murraysetnosy: + barry
messages: + msg162561
2012-06-09 09:55:20bruno.Piguetsetfiles: + patch_netrc_2.6.txt

messages: + msg162556
2012-06-02 19:02:09r.david.murraysetpriority: normal -> high

type: security
components: + Library (Lib)
versions: + Python 2.7, Python 3.2, Python 3.3
nosy: + r.david.murray

messages: + msg162165
2012-06-02 12:54:19bruno.Piguetsettitle: netrc module alows read of non-secured .netrc file -> netrc module allows read of non-secured .netrc file
2012-06-02 12:53:41bruno.Piguetcreate