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

proposal: 1.12.2 (50.5.2) move/merge to 12.5.2 (50.5.1) #1406

Closed
elarlang opened this issue Oct 21, 2022 · 22 comments · Fixed by #1413 or #2156
Closed

proposal: 1.12.2 (50.5.2) move/merge to 12.5.2 (50.5.1) #1406

elarlang opened this issue Oct 21, 2022 · 22 comments · Fixed by #1413 or #2156
Assignees
Labels
4b Major-rework These issues need to be part of a full chapter rework 6) PR awaiting review V50 Group issues related to Web Frontend _5.0 - prep This needs to be addressed to prepare 5.0

Comments

@elarlang
Copy link
Collaborator

elarlang commented Oct 21, 2022

Related issue:

# Description L1 L2 L3 CWE
1.12.2 Verify that user-uploaded files - if required to be displayed or downloaded from the application - are served by either octet stream downloads, or from an unrelated domain, such as a cloud file storage bucket. Implement a suitable Content Security Policy (CSP) to reduce the risk from XSS vectors or other attacks from the uploaded file. 646

edit: CSP part is now removed from the requirement text.

CWE-646 - Reliance on File Name or Extension of Externally-Supplied File

Current requirement contains many parts:

  • are served by either octet stream downloads, or from an unrelated domain, such as a cloud file storage bucket
  • Implement a suitable Content Security Policy (CSP) to reduce the risk from XSS vectors.
    • Point: duplicates clearly Content-Security-Policy requirement
    • Covered by current 14.4.3
  • or other attacks from the uploaded file
    • Point: "other point" (none)
# Description L1 L2 L3 CWE
12.5.2 Verify that direct requests to uploaded files will never be executed as HTML/JavaScript content. 434
14.4.3 [MODIFIED] Verify that a Content Security Policy (CSP) response header is in place that helps mitigate impact for XSS attacks like HTML, DOM, CSS, JSON, and JavaScript injection vulnerabilities. 1021

CWE-434 - Unrestricted Upload of File with Dangerous Type

Proposals:

  • remove duplicate CSP part from the requirement (done, duplicate removed)
  • merge 1.12.2 to 12.5.2 as those serve the same goal
@elarlang elarlang self-assigned this Oct 21, 2022
elarlang added a commit that referenced this issue Nov 5, 2022
elarlang added a commit that referenced this issue Nov 5, 2022
@elarlang elarlang linked a pull request Nov 5, 2022 that will close this issue
tghosth pushed a commit that referenced this issue Nov 6, 2022
@elarlang elarlang reopened this Nov 6, 2022
@elarlang elarlang added the 3) awaiting proposal There is some discussion in issue and reach to some results but it's not concluded with clear propos label Nov 6, 2022
@elarlang elarlang changed the title proposal: cleanup 1.12.2 and move/merge to 12.5.2 proposal: 1.12.2 move/merge to 12.5.2 Nov 6, 2022
@tghosth
Copy link
Collaborator

tghosth commented Nov 21, 2022

Why did you reopen @elarlang?

@elarlang
Copy link
Collaborator Author

Why did you reopen @elarlang?

Only CSP part remove quick-fix is done, merge to make.

@tghosth tghosth added _5.0 - prep This needs to be addressed to prepare 5.0 josh/elar labels Dec 7, 2022
@tghosth
Copy link
Collaborator

tghosth commented Jan 25, 2023

Requirement history:

# Description L1 L2 L3 CWE
1.12.2 [MODIFIED] Verify that user-uploaded files - if required to be displayed or downloaded from the application - are served by either octet stream downloads, or from an unrelated domain, such as a cloud file storage bucket. 646
1.12.2 Verify that user-uploaded files - if required to be displayed or downloaded from the application - are served by either octet stream downloads, or from an unrelated domain, such as a cloud file storage bucket. Implement a suitable Content Security Policy (CSP) to reduce the risk from XSS vectors or other attacks from the uploaded file. 646
1.12.2 Verify that user-uploaded files - if required to be displayed or downloaded by the application - are served from an unrelated domain, such as a cloud file storage bucket or similar, to reduce the risk of image or other files exploiting XSS vectors via using content security policy and same origin policy restrictions. 646

The item was originally added in commit 7809c0b.

Based on the discussion in #455, it sounds like the main purpose was to promote sandboxing and not just for XSS but in general.

I would support keeping this as a separate requirement but moving it to section 12.5 as a practical/implementation requirement.

@elarlang
Copy link
Collaborator Author

Mapping it here: #1009

@jmanico
Copy link
Member

jmanico commented Feb 17, 2023

Suggest a small grammar change for 1.12.2 (please do not use dashes in requirements, they are not proper punctuation).

1.12.2 [MODIFIED] Verify that user-uploaded files, if required to be displayed or downloaded from the application, are served by either octet-stream downloads or an unrelated domain, such as a cloud file storage bucket.   646

@tghosth tghosth added 4a) Waiting for another This issue is waiting for another issue to be resolved and removed 3) awaiting proposal There is some discussion in issue and reach to some results but it's not concluded with clear propos labels May 28, 2023
@tghosth tghosth added 4b Major-rework These issues need to be part of a full chapter rework V12 labels Jul 10, 2023
elarlang pushed a commit to elarlang/ASVS that referenced this issue Dec 15, 2023
@elarlang elarlang changed the title proposal: 1.12.2 move/merge to 12.5.2 proposal: 1.12.2 (50.5.2) move/merge to 12.5.2 (50.5.1) Dec 15, 2023
@elarlang
Copy link
Collaborator Author

Update: those requirements are moved now to the Web Frontend Security category:

V50.5 Unintended Content Interpretation

# Description L1 L2 L3 CWE
50.5.1 [GRAMMAR, MOVED FROM 12.5.2] Verify that direct requests to uploaded files will never be executed as HTML and JavaScript content. 434
50.5.2 [MODIFIED, MOVED FROM 1.12.2] Verify that user-uploaded files - if required to be displayed or downloaded from the application - are served by either octet stream downloads, or from an unrelated domain, such as a cloud file storage bucket. 646

Proposal to merge them is still valid.

@tghosth
Copy link
Collaborator

tghosth commented Dec 28, 2023

So we now also have:

# Description L1 L2 L3 CWE
50.5.3 [ADDED, DEPRECATES 14.4.2] Verify that to prevent browsers from rendering content or functionality in HTTP responses in an incorrect context, security controls are in place (e.g. not serving the content unless headers indicate it is the correct context, Content-Security-Policy: sandbox, Content-Disposition: attachment, etc). For example when an API or other resource is loaded directly.

This seems to replace 50.5.1 definitely. What about 50.5.2?

@tghosth tghosth added V50 Group issues related to Web Frontend and removed V12 labels Jun 19, 2024
@tghosth
Copy link
Collaborator

tghosth commented Jun 19, 2024

@elarlang any idea what the next stage is here

@elarlang
Copy link
Collaborator Author

The next step is to build a requirement for addressing the attack vector, that an attacker can upload a file that causes a so-called XSS attack in the same origin scope when accessed directly or served incorrectly.

But to have the brainpower to do that is another question.

@elarlang elarlang removed the 4a) Waiting for another This issue is waiting for another issue to be resolved label Jun 19, 2024
@jmanico
Copy link
Member

jmanico commented Jun 20, 2024

Do one of these work for you?

Verify that user-uploaded files, if required to be displayed or downloaded from the application, are served by an octet stream downloads and from an unrelated domain, such as a cloud file storage bucket.

or

Verify that user-uploaded files, if required to be displayed or downloaded from the application, are served from an unrelated domain, such as a cloud file storage bucket, to mitigate XSS and other security risks.

@elarlang
Copy link
Collaborator Author

elarlang commented Oct 1, 2024

From @tghosth in #1406 (comment) about 50.5.3

This seems to replace 50.5.1 definitely. What about 50.5.2?

The more I try to solve the issue, the more I also lean towards a solution to merge them all into one requirement. As the principle is already covered, we should spotlight the uploaded files issue in one example at the end of the requirement.

This requirement can be long - it covers so many edge-cases and there are so many different solutions to achieve that.

@jmanico
Copy link
Member

jmanico commented Oct 2, 2024

How about one of these?

Verify that user-uploaded files, if required to be displayed or downloaded from the application, are handled in a manner that ensures they cannot be executed as HTML or JavaScript content. This can be achieved by serving files as octet-stream downloads with appropriate Content-Disposition and Content-Type headers, or by serving them from an unrelated domain (such as a cloud file storage bucket), to mitigate XSS and other security risks.

or

Verify that user-uploaded files, if required to be displayed or downloaded from the application, are served in a manner that prevents execution as HTML or JavaScript content. Files must be delivered either through octet-stream downloads or from an unrelated domain (such as a cloud storage bucket), with appropriate security headers and validation mechanisms to mitigate risks such as XSS and MIME-type attacks.

@elarlang
Copy link
Collaborator Author

elarlang commented Oct 2, 2024

The overlap with 50.5.3 is quite big - the only recommendation that is different is that "serve the content from other domain". Although it takes the same-origin vector down, I'm not sure we should mandate or allow HTML or JavaScript execution from other domain. If there is no reason to execute it with direct HTTP request, then it should not happen.

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

tghosth commented Oct 15, 2024

haha so now we also have 50.5.4. Reproducing the whole section here:

# Description L1 L2 L3 CWE
50.5.1 [GRAMMAR, MOVED FROM 12.5.2] Verify that direct requests to uploaded files will never be executed as HTML and JavaScript content. 434
50.5.2 [MODIFIED, MOVED FROM 1.12.2] Verify that user-uploaded files - if required to be displayed or downloaded from the application - are served by either octet stream downloads, or from an unrelated domain, such as a cloud file storage bucket. 646
50.5.3 [ADDED, DEPRECATES 14.4.2] Verify that security controls are in place to prevent browsers from rendering content or functionality in HTTP responses in an incorrect context (e.g., when an API or other resource is loaded directly). Possible controls could include: not serving the content unless headers indicate it is the correct context, Content-Security-Policy: sandbox, Content-Disposition: attachment, etc.
50.5.4 [ADDED, SPLIT FROM 5.3.3] Verify that context-aware methods are used when handling untrusted data to avoid unintended content execution, such as executing content as HTML instead of displaying it as text.

@tghosth
Copy link
Collaborator

tghosth commented Oct 15, 2024

@elarlang how many requirements do you think this should be merged down to?

@elarlang
Copy link
Collaborator Author

elarlang commented Oct 15, 2024

50.5.1, 50.5.2 and 50.5.3 are for situation, if an HTTP response is executed as HTML or JavaScript (or anything else). Those 3 can be merged to one requirement. The question is mostly, should we have a separate requirement for uploaded files to highlight the widespread issue.

50.5.4 is a separate thing - it is more related to, how dynamic JavaScript builds the HTML document.

@jmanico
Copy link
Member

jmanico commented Oct 15, 2024

Agreed on 50.5.1, 50.5.2 and 50.5.3 merging. How about:

Verify that user-uploaded files are never executed as HTML or JavaScript, are served as octet stream downloads or from a separate domain, and implement controls (e.g., Content-Security-Policy: sandbox, Content-Disposition: attachment) to prevent incorrect rendering by browsers.

@elarlang
Copy link
Collaborator Author

elarlang commented Oct 15, 2024

Jim - you are cutting so many details and keep proposing a separate domain. Please read previous comments.

I prefer we just cover 50.5.1 and 50.5.2 points into current 50.5.3:

Verify that security controls are in place to prevent browsers from rendering content or functionality in HTTP responses in an incorrect context (e.g., when an API, a user-uploaded file or other resource is requested directly). Possible controls could include: not serving the content unless HTTP request headers, such as Sec-Fetch-*, indicate it is the correct context, Content-Security-Policy: sandbox, Content-Disposition: attachment, etc.

edit: finetuned the last sentense

@jmanico
Copy link
Member

jmanico commented Oct 15, 2024

Sorry @elarlang was moving too fast. I like your version. All is well.

@elarlang
Copy link
Collaborator Author

Tags (the idea: 12.5.2 was moved to 50.5.1 and other 2 requirements were merged into it):

  • to new merged requirement [MODIFIED, MOVED FROM 12.5.2, MERGED FROM 1.12.2, 14.4.2]
  • 12.5.2 [MOVED TO 50.5.1]
  • 1.12.2 [DELETED, MERGED TO 50.5.1]
  • 14.4.2 [DELETED, MERGED TO 50.5.1] - previously it the new requirement said "DEPRECATES 14.4.2"

@elarlang elarlang removed josh/elar next meeting Filter for leaders labels Oct 15, 2024
@elarlang
Copy link
Collaborator Author

ping @tghosth - please recheck before I hit the PR.

@elarlang elarlang added the 4) proposal for review Issue contains clear proposal for add/change something label Oct 15, 2024
@tghosth
Copy link
Collaborator

tghosth commented Oct 15, 2024

@elarlang that all makes sense to me

@elarlang elarlang added the 5) awaiting PR A proposal hs been accepted and reviewed and we are now waiting for a PR label Oct 16, 2024
elarlang pushed a commit to elarlang/ASVS that referenced this issue Oct 16, 2024
@elarlang elarlang added 6) PR awaiting review and removed 4) proposal for review Issue contains clear proposal for add/change something 5) awaiting PR A proposal hs been accepted and reviewed and we are now waiting for a PR labels Oct 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
4b Major-rework These issues need to be part of a full chapter rework 6) PR awaiting review V50 Group issues related to Web Frontend _5.0 - prep This needs to be addressed to prepare 5.0
Projects
None yet
3 participants