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

user-submitted filename metadata (V12.3) #1427

Closed
Sjord opened this issue Nov 17, 2022 · 28 comments
Closed

user-submitted filename metadata (V12.3) #1427

Sjord opened this issue Nov 17, 2022 · 28 comments
Assignees
Labels
1) Discussion ongoing Issue is opened and assigned but no clear proposal yet 4b Major-rework These issues need to be part of a full chapter rework 4) proposal for review Issue contains clear proposal for add/change something Community wanted We would like feedback from the community to guide our decision otherwise we will progress next meeting Filter for leaders V12 _5.0 - prep This needs to be addressed to prepare 5.0

Comments

@Sjord
Copy link
Contributor

Sjord commented Nov 17, 2022

ASVS/0x20-V12-Files-Resources.md at master · OWASP/ASVS · GitHub

# Description L1 L2 L3 CWE
12.3.1 Verify that user-submitted filename metadata is not used directly by system or framework filesystems and that a URL API is used to protect against path traversal. 22
12.3.2 Verify that user-submitted filename metadata is validated or ignored to prevent the disclosure, creation, updating or removal of local files (LFI). 73
12.3.3 Verify that user-submitted filename metadata is validated or ignored to prevent the disclosure or execution of remote files via Remote File Inclusion (RFI) or Server-side Request Forgery (SSRF) attacks. 98
12.3.5 Verify that untrusted file metadata is not used directly with system API or libraries, to protect against OS command injection. 78

I think "filename metadata" is incorrect here. It would be information about the filename, not the filename itself.

I think "filename metadata" should be either "filename" or "file metadata". I would prefer "file metadata", as that would include both the filename and content-type, and any other file information sent by the client.

@elarlang
Copy link
Collaborator

elarlang commented Nov 20, 2022

Oh, I have postponed to reorganize this section as I have some big tasks here opened already, but in this section are so many things which are incorrect or I just don't like (#1136 (comment)). For a starter:

  • user-submitted - unnecessary limitation, should be for every filename or metainfo an application processes
  • in general we should just say - filename and metainfo are user input and we can use other requirements in V5 category
  • 12.3.1 - no clear path traversal requirement in kind of covered in V5.2.2
  • 12.3.2 - overlaps with 5.2.6, 5.3.9
  • 12.3.3 - overlaps with 5.2.6, 5.3.9
  • 12.3.5 - duplicate with 5.3.8

Related requirements:

# Description L1 L2 L3 CWE
5.2.2 Verify that unstructured data is sanitized to enforce safety measures such as allowed characters and length. 138
5.2.6 Verify that the application protects against SSRF attacks, by validating or sanitizing untrusted data or HTTP file metadata, such as filenames and URL input fields, and uses allow lists of protocols, domains, paths and ports. 918
5.3.8 Verify that the application protects against OS command injection and that operating system calls use parameterized OS queries or use contextual command line output encoding. (C4) 78
5.3.9 Verify that the application protects against Local File Inclusion (LFI) or Remote File Inclusion (RFI) attacks. 829

edit: update 2024-09-04. Requirement 5.3.9 is deleted as duplicate of 12.3.2, 12.3.3.

@elarlang elarlang changed the title user-submitted filename metadata user-submitted filename metadata (V12.3) Nov 20, 2022
@tghosth tghosth added Community wanted We would like feedback from the community to guide our decision otherwise we will progress josh/elar 1) Discussion ongoing Issue is opened and assigned but no clear proposal yet _5.0 - prep This needs to be addressed to prepare 5.0 labels Dec 7, 2022
@elarlang
Copy link
Collaborator

elarlang commented Dec 22, 2022

I think this entire "#V12.3 File Execution" should be moved away from V12 - all other requirements in V12 are more related to handling user-uploaded or application generated files as content.

V12.6.1 is already waiting to be moved away but there is no clear-good category yet (#1343).

From V12.3:

  • 12.3.1 path traversal - should be in validation + sanitization
  • 12.3.2 local file - the point is the same with path traversal, it should be not possible to manipulate the path where the resource is created/read/deleted
  • 12.3.3 - do we actually need this requirement? from rfi point of view, if 12.3.1 and 12.3.2 are done well, this problem can not exists. ssrf part is covered by 5.2.6
  • 12.3.5 cmd injection - merge to 5.3.8 (I opened separate issue proposal: delete 12.3.5 as duplicate of 5.3.8 #1472 for that)
  • 12.3.6 this is more malicous code execution from external sources, V10 category topic. merge to 10.3.2 (I opened separate issue proposal: merge 12.3.6 to 10.3.2 #1471 for that)

@tghosth tghosth removed the josh/elar label Dec 28, 2022
@tghosth tghosth assigned tghosth and unassigned Sjord and elarlang Dec 28, 2022
@tghosth
Copy link
Collaborator

tghosth commented Dec 28, 2022

@set-reminder 3 weeks @tghosth to look at this

@octo-reminder
Copy link

octo-reminder bot commented Dec 28, 2022

Reminder
Wednesday, January 18, 2023 12:00 AM (GMT+01:00)

@tghosth to look at this

@tghosth
Copy link
Collaborator

tghosth commented Dec 29, 2022

My interpretation is that 12.3.1 is talking about path traversal leading to arbitrary file download and 12.3.2 is talking about using a the filename provided to upload functionality to control where a file is stored, e.g. leading to deleting a sensitive file or a webshell. This seems to be supported by the relevant CWE descriptions.

Regardless I agree that the section needs rework.

@elarlang
Copy link
Collaborator

Category name for 12.3 is file execution - not file upload (which is separate category 12.1) or file download (which is separate category 12.5)

12.3.1 There are many ways how to reach to file download. For example access control problems - files stored in public folder or IDOR, but we don't duplicate V4 requirements in V12. The same way I think we should handle input validation / sanitization problem in V5 category.

12.3.2/12.3.3 as mentioning LFI and RFI are clear file execution requirements, which is impact. Base problem is still not validated path or url when resource is loaded. Abstractly the same problem as 12.3.1 - "arbitrary resource loading". Again there can be alternative ways how to reach to arbitrary resource loading - using again architecture problems, uploading PHP files (as LFI and RFI mostly are PHP related) to public folder - access it directly and effect is the same.

Should we get in some file processing requirements like handling zip files and then see, how we need to change/create categories for them:

@tghosth
Copy link
Collaborator

tghosth commented Jan 15, 2023

History for 12.3.3:

# Description L1 L2 L3 CWE
12.3.3 Verify that user-submitted filename metadata is validated or ignored to prevent the disclosure or execution of remote files via Remote File Inclusion (RFI) or Server-side Request Forgery (SSRF) attacks. 98
12.3.3 Verify that user-submitted filename metadata is validated or ignored to prevent the disclosure or execution of remote files (RFI), which may also lead to SSRF. 98
16.4 Verify that untrusted data is not used within inclusion, class loader, or reflection capabilities to prevent remote/local code execution vulnerabilities. tbd

(That last one is not 100% match)

@octo-reminder
Copy link

octo-reminder bot commented Jan 17, 2023

🔔 @tghosth

@tghosth to look at this

@tghosth tghosth added 4b Major-rework These issues need to be part of a full chapter rework V12 V5 Temporary label for grouping input validation, sanitization, encoding, escaping related requirements labels May 23, 2023
@tghosth
Copy link
Collaborator

tghosth commented Aug 12, 2024

This was tagged as V5 but my inclination is to keep it as V12 as it is specific to files and V5 is a little overloaded :)

@tghosth tghosth removed the V5 Temporary label for grouping input validation, sanitization, encoding, escaping related requirements label Aug 12, 2024
@jmanico
Copy link
Member

jmanico commented Sep 4, 2024

This thread got out of hand. I want to address the original posters comments.

  1. I think "filename metadata" is incorrect here. It would be information about the filename, not the filename itself.
  2. I think "filename metadata" should be either "filename" or "file metadata". I would prefer "file metadata", as that would include both the filename and content-type, and any other file information sent by the client.

I think these comments are spot on and need to be addressed. Here are my thoughts on how to address the OP and how to fix these problems.

12.3.1 Verify that the user-submitted filename or file metadata is not used directly when creating filepaths for stored files to protect against path traversal. 22
12.3.2 Verify that user-submitted filenames or file metadata is validated or ignored to prevent the disclosure, creation, updating or removal of local files (LFI). 73
12.3.3 Verify that user-submitted filenames or file metadata is validated or ignored to prevent the disclosure or execution of remote files via Remote File Inclusion (RFI) or Server-side Request Forgery (SSRF) attacks. 98
12.3.5 Verify that user-submitted filenames or file metadata is not used directly with system API or libraries, to protect against OS command injection. 78

I think these are all necessary to ensure that this section (v12) is complete to help folks build secure file uploaded features.

@elarlang
Copy link
Collaborator

elarlang commented Sep 4, 2024

note that 12.3.5 is removed as duplicate of 5.3.8

My previous comment (#1427 (comment)):

  • 12.3.1 path traversal - should be in validation + sanitization
  • 12.3.2 local file - the point is the same with path traversal, it should be not possible to manipulate the path where the resource is created/read/deleted
  • 12.3.3 - do we actually need this requirement? from rfi point of view, if 12.3.1 and 12.3.2 are done well, this problem can not exists. ssrf part is covered by 5.2.6

Proposal from Jim is ok from wording perspective, but I question the need to have 3 separate requirements for the same problem in the program code with just having 3 different attack codes to test them.

  • 12.3.1 - path traversal when writing a file
  • 12.3.2 - non-validated/sanitized userinput that may cause path traversal and/or using full path for files for any operation with files
  • 12.3.3 - the same as 12.3.2 but using full url's as input

Many situations in vulnerable program codes matches all 3 at the same time.

@jmanico
Copy link
Member

jmanico commented Sep 5, 2024

Good call Elar. How about we merge these into one, something like:

12.3.1 Verify that the user-submitted filename or file metadata is not used directly when creating filepaths for stored files to protect against path traversal, SSRF, LFI and similar attacks that use filename and filename metadata from untrusted sources. 22

@elarlang elarlang added the next meeting Filter for leaders label Sep 5, 2024
@tghosth
Copy link
Collaborator

tghosth commented Sep 5, 2024

Merged looks great, @elarlang to do some wording fine tuning

@tghosth tghosth assigned elarlang and unassigned tghosth Sep 5, 2024
@tghosth tghosth removed the next meeting Filter for leaders label Sep 5, 2024
@elarlang
Copy link
Collaborator

elarlang commented Sep 5, 2024

To also have positive requirement, just some example for the direction:

Verify that file operations are safe from manipulating the resource path or address with data from untrusted sources - using validation and sanitization to avoid path traversal, local- or remote file inclusion, and server-side request forgery attacks.

@jmanico
Copy link
Member

jmanico commented Sep 5, 2024

I'd rather not suggest validation or sanitization (this is just too error prone with file operations) and instead just avoid user data for file operations all together. My suggestion:

Verify that file operations do not use user-submitted filenames or file metadata when creating filepaths to protect against path traversal, local or remote file inclusion (LFI/RFI), and server-side request forgery (SSRF) attacks, by preventing manipulation of resource paths with data from untrusted sources.

@elarlang
Copy link
Collaborator

elarlang commented Sep 5, 2024

I don't think it is a realistic suggestion and it is against widespread reality how the application handling uploaded file names (for example). If you upload an attachment to be sent via email, you could suggest that the uploaded file does not have the same name you just uploaded?

@jmanico
Copy link
Member

jmanico commented Sep 5, 2024

You can upload a file and use an internal trusted name (like an ID) and still preserve the filename for display only. You do not ever need to use the filename for actual file-IO. This is a very common secure dev practice.

@elarlang
Copy link
Collaborator

elarlang commented Sep 5, 2024

Explanation makes sense, but as one valid option how to do that. If there is validation and sanitization that gives defense, we can not say it is wrong.

Let's say there is situation, that only letter and numbers are kept in the user input, with max length 50 symbols and stored as file name. Someone is watching ASVS requirement and points out that the application is not valid for ASVS...

@jmanico
Copy link
Member

jmanico commented Sep 5, 2024 via email

@elarlang
Copy link
Collaborator

elarlang commented Sep 5, 2024

Yes, this is ok.

@jmanico
Copy link
Member

jmanico commented Sep 5, 2024

How about this for 12.3.1 (and we eliminate 12.3.2 and 12.3.3) (and 12.3.4 and 12.3.5 are already removed from v12)

Verify that file operations do not use user-submitted filenames or file metadata when creating filepaths to protect against path traversal, local or remote file inclusion (LFI/RFI), and server-side request forgery (SSRF) attacks, by preventing manipulation of resource paths with data from untrusted sources. If user-submitted filenames or file metadata must be used in file operations then use strict validation and sanitization.

@tghosth tghosth added the next meeting Filter for leaders label Sep 8, 2024
@tghosth
Copy link
Collaborator

tghosth commented Sep 12, 2024

@elarlang to confirm on this

@tghosth
Copy link
Collaborator

tghosth commented Sep 18, 2024

@elarlang ping :)

@elarlang
Copy link
Collaborator

Sorry for delay.

At the moment the proposed requirement covers all the points but is focused on what not to do, instead of what to do.

@jmanico
Copy link
Member

jmanico commented Sep 18, 2024

How about:

Verify that file operations avoid using user-submitted filenames or file metadata when creating filepaths to protect against path traversal, local/remote file inclusion (LFI/RFI), and server-side request forgery (SSRF) attacks. Instead, use internal, trusted data for file I/O. If user-submitted filenames or file metadata must be used, apply strict validation and sanitization.

@elarlang
Copy link
Collaborator

elarlang commented Sep 19, 2024

With few changes:

Verify that file operations avoid using user-submitted filenames or file metadata when creating file paths to protect against path traversal, local or remote file inclusion (LFI, RFI), and server-side request forgery (SSRF) attacks. Instead, use internal, trusted data for file I/O. If user-submitted filenames or file metadata must be used, strict validation and sanitization must be applied.

If it looks ok, I'll handle the PR and related modification tags.

@elarlang elarlang added the 4) proposal for review Issue contains clear proposal for add/change something label Sep 19, 2024
@jmanico
Copy link
Member

jmanico commented Sep 19, 2024 via email

elarlang pushed a commit to elarlang/ASVS that referenced this issue Sep 20, 2024
@elarlang elarlang mentioned this issue Sep 20, 2024
@elarlang
Copy link
Collaborator

elarlang commented Sep 22, 2024

Updated:

# Description L1 L2 L3 CWE
12.3.1 [MODIFIED, MERGED FROM 12.3.2, 12.3.3, 5.3.9] Verify that file operations avoid using user-submitted filenames or file metadata when creating file paths to protect against path traversal, local or remote file inclusion (LFI, RFI), and server-side request forgery (SSRF) attacks. Instead, use internal, trusted data for file I/O. If user-submitted filenames or file metadata must be used, strict validation and sanitization must be applied. 73

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
1) Discussion ongoing Issue is opened and assigned but no clear proposal yet 4b Major-rework These issues need to be part of a full chapter rework 4) proposal for review Issue contains clear proposal for add/change something Community wanted We would like feedback from the community to guide our decision otherwise we will progress next meeting Filter for leaders V12 _5.0 - prep This needs to be addressed to prepare 5.0
Projects
None yet
Development

No branches or pull requests

4 participants