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

5.3.1 has too much going on and should be shortened #1589

Closed
tghosth opened this issue Mar 22, 2023 · 95 comments · Fixed by #2026
Closed

5.3.1 has too much going on and should be shortened #1589

tghosth opened this issue Mar 22, 2023 · 95 comments · Fixed by #2026
Assignees
Labels
7) PR in non-master branch V5 Temporary label for grouping input validation, sanitization, encoding, escaping related requirements _5.0 - prep This needs to be addressed to prepare 5.0

Comments

@tghosth
Copy link
Collaborator

tghosth commented Mar 22, 2023

5.3.1 Verify that output encoding is relevant for the interpreter and context required. For example, use encoders specifically for HTML values, HTML attributes, JavaScript, URL parameters, HTTP headers, SMTP, and others as the context requires, especially from untrusted inputs (e.g. names with Unicode or apostrophes, such as ねこ or O'Hara). (C4)
@tghosth tghosth added 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 Community wanted We would like feedback from the community to guide our decision otherwise we will progress labels Mar 22, 2023
@tghosth
Copy link
Collaborator Author

tghosth commented Mar 22, 2023

Point from @ImanSharaf #1561 (comment)

Thank you for your response and for pointing out that ASVS 5.3.1 does technically cover CRLF Injection in HTTP headers. However, I would like to express my concern that the current wording of 5.3.1 might not explicitly highlight the importance of testing for CRLF Injection attacks. As a result, testers might inadvertently overlook this specific attack vector when performing security assessments.

@elarlang
Copy link
Collaborator

We also should address CSS related issue with this: #1558

@elarlang
Copy link
Collaborator

elarlang commented Mar 23, 2023

(updated 2023-03-29, 2023-03-30)

As the Pandora box is opened...

We still need to have abstract requirement to cover all not listed syntaxes:

Verify that output encoding is relevant for the interpreter and context required.

Separate requirements:

  • HTML values, HTML attributes
    • can we add here XML values and XML attributes and split up XMl encoding and XPath sanitize from 5.3.10 need more beef #1556
    • the problem here is, "HTML attributes" should be "HTML attribute values". For HTML attributes encoding is not helpful and validation against allow-list and/or sanitation need to be used.
  • JavaScript - for JavaScript is available escaping or encoding, both should be covered
    • Maybe we can merge it to current 5.3.3 (need to rethink DOM XSS part from there)
  • URL encoding
  • HTTP headers
  • SMTP - is there such thing like "SMTP encoding?" or we actually should name it Content-Transfer-Encoding?

I did not cover from 5.3.1 - do we need to mention it?

especially from untrusted inputs (e.g. names with Unicode or apostrophes, such as ねこ or O'Hara).

CSS - (for some reason it is missing from issue description but actually exists in bleeding edge version) - As there is no such thing like CSS encoding, we need to use input validation and/or sanitize when using userinput in CSS. Should be covered via #1558

@elarlang elarlang added the V5 Temporary label for grouping input validation, sanitization, encoding, escaping related requirements label Apr 5, 2023
@jmanico
Copy link
Member

jmanico commented Apr 5, 2023

Note: CSS encoding is a thing, it's a native JS function. CSS.escape for example.

@elarlang elarlang added the next meeting Filter for leaders label Apr 29, 2023
@tghosth tghosth added the 4b Major-rework These issues need to be part of a full chapter rework label May 23, 2023
@elarlang elarlang removed the next meeting Filter for leaders label Nov 29, 2023
@tghosth
Copy link
Collaborator Author

tghosth commented Feb 15, 2024

I agree that we should split out this requirement as @elarlang has set out above, the treatment should either be one or more of the following:

  • Create new requirement if the particular context does not already have a requirement
  • Reference this issue and what is needed if there is already a related open issue (such as with HTML values, HTML attributes)
  • Make sure that each requirement (existing or new) correctly captures the fix that is needed (encoding, escaping, sanitizing, sandboxing, etc)
  • (Don't move existing requirements around yet)
  • Make sure that an individual requirement is not mixing different treatments or contexts, e.g. we may want to split out SMTP and IMAP.

@elarlang
Copy link
Collaborator

I have started to write those requirements many times.. but those still feel like duplicates. So, there is a turn-around in my proposal, and it is also more aligned with the goals to make fewer requirements to the ASVS and provide "requirement per principle", not "requirement per principle per syntax/technology". We don't have separate requirements for "use authorization correctly in framework x" and "use authorization correctly in framework y", so we also should not have separate requirements for "use encoding correctly for HTML" and "use encoding correctly for URL".

The more I watch the current requirement, the more I think it's ok. Just need to shorten it a bit.

Verify that output encoding is relevant for the interpreter and context required. For example, use encoders specifically for HTML values, HTML attributes, JavaScript, URL parameters, HTTP headers, and SMTP., and others as the context requires, especially from untrusted inputs (e.g. names with Unicode or apostrophes, such as ねこ or O'Hara). (C4)

The list of examples can be fine-tuned. Splitting the requirement per syntax makes it more like a checklist, and this is a testing guide area.

@elarlang elarlang added the next meeting Filter for leaders label Apr 17, 2024
@elarlang
Copy link
Collaborator

For brainstorming - to cover entire chapters 5.2 and 5.3, it's enough to have a requirement:

Verify that the application builds commands and documents without data used and can not change the command and document structure by using relevant defense for the syntax and context required, such as parametrization, encoding, escaping, or sanitization.

Where we can put the line between "too detailed" vs "too abstract".

@jmanico
Copy link
Member

jmanico commented Apr 17, 2024

CSS - (for some reason it is missing from issue description but actually exists in bleeding edge version) - As there is no such thing like CSS encoding, we need to use input validation and/or sanitize when using userinput in CSS. Should be covered via #1558

CSS encoding does exist in native javascript and other languages meant to escape CSS Variables. See: https://developer.mozilla.org/en-US/docs/Web/API/CSS/escape_static

@elarlang
Copy link
Collaborator

Jim, you already said that (#1589 (comment)). Just please, (re)read and learn the issues before commenting :)

@jmanico
Copy link
Member

jmanico commented Apr 18, 2024

Jim, you already said that (#1589 (comment)). Just please, (re)read and learn the issues before commenting :)

Understood and will do.

@elarlang
Copy link
Collaborator

My a bit updated proposal:

Verify that output encoding is relevant for the interpreter and context required, such as encoding value for HTML value, HTML attribute, JavaScript, URL parameter, HTTP header, or SMTP.

@elarlang elarlang added 4) proposal for review Issue contains clear proposal for add/change something and removed next meeting Filter for leaders labels Apr 19, 2024
@jmanico
Copy link
Member

jmanico commented Apr 20, 2024

I like it Elar.

@tghosth
Copy link
Collaborator Author

tghosth commented Apr 21, 2024

So I am not sure I completely understood your draft, does my rephrasing make sense:

Verify that output encoding is relevant for the interpreter and context required, such as encoding the relevant characters for HTML elements, HTML attribute, JavaScript, URL parameter, HTTP header, or SMTP.

@jmanico
Copy link
Member

jmanico commented Jun 2, 2024 via email

@tghosth
Copy link
Collaborator Author

tghosth commented Jun 6, 2024

I think there is still a question here related to document structure which we should discuss further.

Having discussed this further with Elar, the direction becomes a little too general because when you start worrying about building HTML attribute names or element names dynamically or building JSON attribute names dynamically you are getting into the territory of allowing the end user to write their own code as well :) This can't be fixed by encoding so we will leave it for now.

This returns us to how to handle this requirement.

My current feeling is that the fact that the current 5.3.1 requirement is a little too abstract is one of the things that has led to this long discussion.

My current feeling is to have specific requirements which cover the key cases and then a catch-all output encoding for other cases which describes a function's behaviour "takes user input and builds some other representation or command based upon it".

Possible rough splitting for now:

Verify that output encoding for an HTTP response/HTML document/XML document is relevant for the context required, such as encoding the relevant characters for HTML elements, HTML attribute, JavaScript, or HTTP headers, to avoid changing the message or document structure.

Verify that the correct encoding is performed for each context when generating a URL.

Verify that the correct encoding is performed for each context in a JSON document.

@jmanico
Copy link
Member

jmanico commented Jun 6, 2024

Here is a detailed list to consider. Some of these are duplicated from other requirements, admittedly.

HTML Docs

  • Verify that user-generated content in HTML tags is properly encoded.
  • Verify that user-generated content in HTML attributes is properly encoded.
  • Verify that data embedded in JavaScript is encoded using a safe method like JSON encoding or JavaScript-specific encoding functions.
  • Verify that data in CSS contexts is encoded to avoid CSS Injection.
  • Verify that data within JSON documents is properly encoded to prevent injection attacks.
  • Verify that the correct encoding is performed for each context when generating a URL.
  • Verify that HTTP headers generated from user input are properly validated and encoded.
  • Verify that dynamically generated HTML is constructed safely using templates or frameworks that auto-encode outputs.
  • Verify that HTML comments do not contain untrusted user input.

Email

  • Verify that email content and headers do not include untrusted user input without proper encoding and validation.

LDAP

  • Verify that LDAP queries are built using safe methods that separate code from data.

Database

  • Verify that SQL queries use parameterized queries or prepared statements.
  • Verify that ORM (Object-Relational Mapping) frameworks are used correctly to prevent SQL Injection.
  • Verify that stored procedures are designed to accept parameters that use parameterized queries or prepared statements.

XML

  • Verify that XML documents use proper encoding to avoid XML Injection.
  • Verify that input used in XML parsing is validated and entity expansion is disabled.

OS

  • Verify that command-line arguments are properly escaped or use safe API functions.
  • Verify that input used in command execution is properly validated and sanitized.

Logs

  • Verify that input used in log messages is properly encoded and sanitized.

@tghosth
Copy link
Collaborator Author

tghosth commented Jun 13, 2024

@tghosth to draft some requirements that sit in between 1 requirement for all of the above and individual requirements for everyone one of the above.

@tghosth
Copy link
Collaborator Author

tghosth commented Jul 24, 2024

ID Handled Category Requirement Notes
1 HTML Docs Verify that user-generated content in HTML tags is properly encoded. Covered by 5.3.1.
2 HTML Docs Verify that user-generated content in HTML attributes is properly encoded. Covered by 5.3.1.
3 HTML Docs Verify that data embedded in JavaScript is encoded using a safe method like JSON encoding or JavaScript-specific encoding functions. Jim says below that this is sufficiently covered in 5.3.1.
4 HTML Docs Verify that data in CSS contexts is encoded to avoid CSS Injection. Mentioned in both 5.3.1 and 5.2.8. Opened #1994 to discuss/resolve this.
5 HTML Docs Verify that data within JSON documents is properly encoded to prevent injection attacks. Mentioned in 5.3.6 and discussed in #1555
6 HTML Docs Verify that the correct encoding is performed for each context when generating a URL. Being discussed in #1961
7 HTML Docs Verify that HTTP headers generated from user input are properly validated and encoded. Covered by 5.3.1.
8 HTML Docs Verify that dynamically generated HTML is constructed safely using templates or frameworks that auto-encode outputs. Jim says below that this is not sufficiently covered in 5.2.5 and "I think safely building HTML (encoding and similar) and avoiding template injection (avoid server side template assembly) are different controls.". Opened #1998 to discuss this separately.
9 HTML Docs Verify that HTML comments do not contain untrusted user input. Added to 5.3.1 and tracked by #1997.
10 Email Verify that email content and headers do not include untrusted user input without proper encoding and validation. Covered by 5.2.3.
11 LDAP Verify that LDAP queries are built using safe methods that separate code from data. Covered by 5.3.7
12 Database Verify that SQL queries use parameterized queries or prepared statements. Covered by 5.3.4.
13 Database Verify that ORM (Object-Relational Mapping) frameworks are used correctly to prevent SQL Injection. Covered by 5.3.4.
14 Database Verify that stored procedures are designed to accept parameters that use parameterized queries or prepared statements. Opened #1993 to include this in 5.3.4.
15 XML Verify that XML documents use proper encoding to avoid XML Injection. Covered by 5.3.10.
16 XML Verify that input used in XML parsing is validated and entity expansion is disabled. XXE is covered in 5.3.10 and schema validation is in 13.3.1.
17 OS Verify that command-line arguments are properly escaped or use safe API functions. Covered in 5.3.8.
18 OS Verify that input used in command execution is properly validated and sanitized. Covered in 5.3.8.
19 Logs Verify that input used in log messages is properly encoded and sanitized. Covered in 7.3.1.

@jmanico
Copy link
Member

jmanico commented Jul 24, 2024

"Verify that data embedded in JavaScript is encoded using a safe method like JSON encoding or JavaScript-specific encoding functions." @jmanico do you think this is sufficiently covered in 5.2.5?

Politely, no. I think safely building HTML (encoding and similar) and avoiding template injection (avoid server side template assembly) are different controls.

@jmanico
Copy link
Member

jmanico commented Jul 24, 2024

"Verify that data embedded in JavaScript is encoded using a safe method like JSON encoding or JavaScript-specific encoding functions." @jmanico do you think this is sufficiently covered in 5.3.1?

Yes, for sure.

@jmanico
Copy link
Member

jmanico commented Jul 24, 2024

I think we need both 5.2.8 and 5.3.1
5.2.8 | Verify that the application sanitizes, disables, or sandboxes user-supplied scriptable or expression template language content, such as Markdown, CSS or XSL stylesheets, BBCode, or similar.
-- | --

This addresses sanitizing user authored cunks of CSS. Just like untrusted HTML is need to be sanitized.

5.3.1 | [MODIFIED] Verify that output encoding is relevant for the interpreter and context required. For example, use encoders specifically for HTML values, HTML attributes, JavaScript, CSS, URL parameters, HTTP headers, SMTP, and others as the context requires, especially from untrusted inputs (e.g. names with Unicode or apostrophes, such as ねこ or O'Hara).
-- | --

This addresses adding user controlled data, like a color, into blocks of otherwise static css. Different controls and to some degree different attacks, too.

This was referenced Jul 24, 2024
@tghosth
Copy link
Collaborator Author

tghosth commented Jul 24, 2024

I updated the table above.

tghosth added a commit that referenced this issue Jul 24, 2024
@tghosth
Copy link
Collaborator Author

tghosth commented Jul 24, 2024

I merged this in. I added a catch all for any encoding scenarios not covered elsewhere as I suggested here.

I don't think this wording is perfect but it has taken too long to spend further on it for now.

@elarlang
Copy link
Collaborator

I merged this in. I added a catch all for any encoding scenarios not covered elsewhere #1589 (comment).

# Description L1 L2 L3 CWE
5.3.1 [MODIFIED] Verify that output encoding for an HTTP response/HTML document/XML document is relevant for the context required, such as encoding the relevant characters for HTML elements, HTML attributes, HTML comments, JavaScript, CSS, or HTTP headers, to avoid changing the message or document structure. 116
5.3.14 [ADDED] Verify that output encoding is relevant for the interpreter and context required in any context where a potentially dangerous interpreter, not mentioned above, is being used.

I prefer to not have the 5.3.14 and have 5.3.1 to cover all cases.

The requirement text must be independent and understandable when watched just a requirement alone - it can not contain "not mentioned above".

@elarlang elarlang reopened this Jul 26, 2024
@tghosth
Copy link
Collaborator Author

tghosth commented Jul 28, 2024

I'd really rather keep 5.3.1 focused on it's particular area. Would it be better to just change the text to say:

[ADDED] Verify that output encoding is relevant for the interpreter and context required in any context where a potentially dangerous interpreter , not mentioned above, is being used.

@jmanico
Copy link
Member

jmanico commented Jul 29, 2024

Looks good @tghosth @elarlang

@tghosth
Copy link
Collaborator Author

tghosth commented Aug 15, 2024

Whilst the concept of a catch-all makes sense, having thought about it more, I don't think it adds that much value compared to adding another, potentially confusing requirement.

@tghosth
Copy link
Collaborator Author

tghosth commented Aug 15, 2024

We also have 5.2.2 as a sort of catch all for dangerous sinks🙃

@tghosth
Copy link
Collaborator Author

tghosth commented Aug 15, 2024

@set-reminder 7 days @tghosth to remove 5.3.14

Copy link

octo-reminder bot commented Aug 15, 2024

Reminder
Thursday, August 22, 2024 12:00 AM (GMT+02:00)

@tghosth to remove 5.3.14

@tghosth tghosth removed the next meeting Filter for leaders label Aug 15, 2024
Copy link

octo-reminder bot commented Aug 21, 2024

🔔 @tghosth

@tghosth to remove 5.3.14

@tghosth
Copy link
Collaborator Author

tghosth commented Aug 25, 2024

5.3.14 should be removed in #2026

@tghosth tghosth linked a pull request Aug 25, 2024 that will close this issue
@tghosth tghosth added 7) PR in non-master branch and removed 4a) Waiting for another This issue is waiting for another issue to be resolved labels Sep 2, 2024
@tghosth tghosth closed this as completed Sep 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
7) PR in non-master branch V5 Temporary label for grouping input validation, sanitization, encoding, escaping related requirements _5.0 - prep This needs to be addressed to prepare 5.0
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants