Bug 1580502 - incron does not escape spaces when passes dir or file names
Summary: incron does not escape spaces when passes dir or file names
Keywords:
Status: ASSIGNED
Alias: None
Product: Fedora EPEL
Classification: Fedora
Component: incron
Version: epel7
Hardware: x86_64
OS: Linux
unspecified
high
Target Milestone: ---
Assignee: Kevin Fenzi
QA Contact: Fedora Extras Quality Assurance
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2018-05-21 15:54 UTC by lejeczek
Modified: 2018-12-05 14:45 UTC (History)
5 users (show)

Fixed In Version:
Doc Type: If docs needed, set a value
Doc Text:
Clone Of:
Environment:
Last Closed:
Type: Bug
Embargoed:


Attachments (Terms of Use)

Description lejeczek 2018-05-21 15:54:41 UTC
Description of problem:

even if you surround args with quotes, eg: "$@"

Maybe never version has it fixed.

Version-Release number of selected component (if applicable):

incron-0.5.10-8.el7.x86_64

How reproducible:


Steps to Reproduce:
1.
2.
3.

Actual results:


Expected results:


Additional info:

Comment 1 Kevin Fenzi 2018-05-24 01:22:45 UTC
Well, there's not a newer version that I am aware of... 

but I will try and take a look and see what I can do when I get some time.

Comment 2 lejeczek 2018-05-24 11:22:49 UTC
would these be only rpm build version? rhel 0.5.10; fedora 0.5.12

Comment 3 Kevin Fenzi 2018-05-25 19:51:35 UTC
Oh yeah, I forgot they moved to github for .11 and .12. you are quite right. 

Can you try this scratch build and see if it solves your issue?

https://koji.fedoraproject.org/koji/taskinfo?taskID=27191722

Comment 4 Stuart D Gathman 2018-12-04 22:20:04 UTC
Spaces are the least of your worries.  

https://github.com/ar-/incron/issues/35

Comment 5 Stuart D Gathman 2018-12-04 22:46:41 UTC
The EPEL package should warn admins that wildcard filenames should NOT be used unless the user and the process by which the filenames are created are fully trusted.

Comment 6 Kevin Fenzi 2018-12-05 00:21:12 UTC
Well, it's running arbitrary commands as root (or a user), I would think it would go without saying that you need to be carefull generating it's configuration. 

Where would such a warning go?

Comment 7 Stuart D Gathman 2018-12-05 04:53:07 UTC
(In reply to Kevin Fenzi from comment #6)
> Well, it's running arbitrary commands as root (or a user), I would think it
> would go without saying that you need to be carefull generating it's
> configuration.

The problem is, it doesn't run the commands in the incrontab, but commands embedded in filenames.  (When using wildcard patterns.)
 
> 
> Where would such a warning go?

For the acme-tiny package (which recommends incron), I put it in a README in %doc along with tips for configuring it to kick sendmail, httpd, when certs are updated.  The best way to avoid the risk is to not use wildcard patterns.  They are no longer safe since incron took the ill advised and incompatible step (with 0.5.11 or 0.5.12) of running a shell command to parse arbitrary filenames (i.e. untrusted strings in most cases).  Note that quoting '$@' does no good, for filenames can contain quotes as well.  And backslashes.

Comment 8 Stuart D Gathman 2018-12-05 05:10:53 UTC
I just checked GetSafePath on 0.5.12, and it is only escaping space and backslash.  If it escaped all shell metachars like bash tab completion does, then it would be a little less dangerous.  As it is, people often have special chars in filenames, and an incrontab watching a directory with, say, album tracks could accidentally do something nasty with song names often containing quotes, semi-colons, ampersand, etc.

If I get a chance, I'll lookup the bash tab completion code to get the list of chars that need to be escaped, and offer a patch.  Then Fedora can include the patch even if upstream never gets around to it.  (It's been years.)

Comment 9 Stuart D Gathman 2018-12-05 05:20:31 UTC
This discussion suggests that if GetSafePath would just escape single quote, you can put the incron path variable in single quotes:

https://stackoverflow.com/questions/15783701/which-characters-need-to-be-escaped-when-using-bash

The second suggestion in the above was to escape everything not in the easy safe set of [a-zA-Z0-9,._+:@%/-]

So I should be able to come up with a patch.

Comment 10 Stuart D Gathman 2018-12-05 14:45:17 UTC
Control chars (also allowed in filenames) also require special treatment.  Patch delayed for further research.  Is there a simple way to go back to using execvp like 0.5.10 for the Fedora package?


Note You need to log in before you can comment on or make changes to this bug.