Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue with .. in filename #28627

Open
Daviid-P opened this issue Mar 4, 2024 · 3 comments
Open

Issue with .. in filename #28627

Daviid-P opened this issue Mar 4, 2024 · 3 comments
Labels
Bug This is a bug (something does not work as expected)

Comments

@Daviid-P
Copy link
Contributor

Daviid-P commented Mar 4, 2024

Bug

// Security:
// We refuse directory transversal change and pipes in file names
if (preg_match('/\.\./', $fullpath_original_file) || preg_match('/[<>|]/', $fullpath_original_file)) {
dol_syslog("Refused to deliver file ".$fullpath_original_file);
print "ErrorFileNameInvalid: ".dol_escape_htmltag($original_file);
exit;
}

I have an invoice that comes from outside and has a ref like XXXXX. so the created file is XXXXX..pdf and .. gets caught.

Could I change it to (?:^|[\/\\\\])\.\.(?:[\/\\\\]|$)

to catch only .. that are meant for path traversal?

/path/to/file
../relative/path
..\\another\\path
C:\\Windows\..\System32/..//././../
file/in/directory/with/..
file\\in\\directory\\with\\..
INVOICE..pdf
file/with/no/../dots
directory\\with\\no\\dots

image

Dolibarr Version

No response

Environment PHP

No response

Environment Database

No response

Steps to reproduce the behavior and expected behavior

No response

Attached files

No response

@Daviid-P Daviid-P added the Bug This is a bug (something does not work as expected) label Mar 4, 2024
@bos4711
Copy link
Contributor

bos4711 commented Mar 7, 2024

Which version?

@Daviid-P
Copy link
Contributor Author

Daviid-P commented Mar 7, 2024

Which version?

The linked code is from develop branch

@bos4711
Copy link
Contributor

bos4711 commented Mar 8, 2024

Sorry, I didn't realize it was a link, I thought it was a screenshot.

Regarding your fix you have a +1 from me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug This is a bug (something does not work as expected)
Projects
None yet
Development

No branches or pull requests

2 participants