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

SONARKT-569 Modify rule S4830: add support for WebViews #4673

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

antonioaversa
Copy link
Contributor

@antonioaversa antonioaversa commented Feb 19, 2025

SONARKT-569

Review

A dedicated reviewer checked the rule description successfully for:

  • logical errors and incorrect information
  • information gaps and missing content
  • text style and tone
  • PR summary and labels follow the guidelines

@antonioaversa antonioaversa marked this pull request as ready for review February 19, 2025 15:00
Copy link
Contributor

@egon-okerman-sonarsource egon-okerman-sonarsource left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needs a few structural changes to be fully "LaYC up-to-date", which we apparently forgot to do for S4830 in Java/Kotlin.

== Resources

include::../common/resources/standards.adoc[]

* https://wiki.sei.cmu.edu/confluence/display/java/MSC61-J.+Do+not+use+insecure+or+weak+cryptographic+algorithms
* CERT - https://wiki.sei.cmu.edu/confluence/display/java/MSC61-J.+Do+not+use+insecure+or+weak+cryptographic+algorithms
* Android Documentation - https://developer.android.com/reference/android/webkit/WebViewClient?hl=en#onReceivedSslError(android.webkit.WebView,%20android.webkit.SslErrorHandler,%20android.net.http.SslError)[WebViewClient.onReceivedSslError] method
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please also link https://support.google.com/faqs/answer/7071387?hl=en which is Google's official remediation


=== Noncompliant code example

[source,kotlin]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interestingly, I can see that the Java and Kotlin documentation was never updated to fully support LaYC. You can look at Docker as an example of the recommended structure.
The source tag needs extra information to support the diff view correctly (and we need to go back and fix this in the other parts of S4830 too).

Suggested change
[source,kotlin]
[source,kotlin,diff-id=101,diff-type=noncompliant]

(diff-id cannot collide with any of the IDs in other languages, which is why I put 101 here.)


include::../../common/fix/validation.adoc[]

==== Implementing a server certificate validation
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Like the comment above, to follow the format correctly, the title here should be renamed

Suggested change
==== Implementing a server certificate validation
==== Compliant solution

and it should be moved above "How to fix it". We generally keep the structure here of:

  • Noncompliant code sample + short explanation if necessary
  • Compliant code sample + short explanation if necessary
  • Longer explanation and possible pitfalls

The text below and code sample are fine otherwise.


Alternatively, you need to implement a validation of the server certificate received in the `SslErrorHandler` object, calling `proceed` and `cancel` appropriately.

[source,kotlin]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
[source,kotlin]
[source,kotlin,diff-id=101,diff-type=compliant]


==== Implementing a server certificate validation

Alternatively, you need to implement a validation of the server certificate received in the `SslErrorHandler` object, calling `proceed` and `cancel` appropriately.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This sentence probably needs a rewrite considering it will be above the common fix text.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I have removed the "Alternatively" and moved above the entire section, so that the two code examples and next to each other, and it makes more sense for them to be in diff with each other.

@antonioaversa
Copy link
Contributor Author

Needs a few structural changes to be fully "LaYC up-to-date", which we apparently forgot to do for S4830 in Java/Kotlin.

As suggested, I have adapted the "How to fix section" to have both compliant and non-compliant code examples, to have a coherent experience with other languages such as docker.

In order to match that, I have moved the ==== Implementing a server certificate validation up, and make it become === Compliant solution, so that the two code snippets are now next to each other, and the code diff between the two makes sense. I have kept the === How does this work? the same as it is in docker and other languages.

Let me know if that looks better for you.

Regarding LaYC: the migration of this rule for Kotlin was done in #2176
In general, I don't think that only having non-compliant makes this section non-fully LaYC compliant, as the "How to fix it" section can have any free structure, if that fits better the story-telling:

This tab could also use a freeform 'story-telling' style if that makes it clearer for the user. Feel free to use any of the titles below, or any other titles you find useful. (ref)

The optionality also applies to "How does this work", and any other level 3 section.

Given the above, I think that the way Java was done looks good to me: the non-compliant code example doesn't have a corresponding compliant, since all the proposed solutions for Java are ways to not use a custom trust manager at all, so I don't think we should bend the structure to meet a LaYC layout which is defined as optional, and proposed as an example of how things should look.

If anything I would remove the ==== Noncompliant code example and === How does this work? titles: the first kind of implies that there is a compliant solution, and the second in my opinion should be the incipit of the entire How to fix section. But I think this is more for a later change, across all languages.

@antonioaversa antonioaversa force-pushed the antonio/SONARKT-569-S4830-add-support-for-webviews branch from d604804 to b11fd7a Compare February 21, 2025 09:37
@egon-okerman-sonarsource
Copy link
Contributor

Regarding LaYC: the migration of this rule for Kotlin was done in #2176
In general, I don't think that only having non-compliant makes this section non-fully LaYC compliant, as the "How to fix it" section can have any free structure, if that fits better the story-telling:

You're right, my previous comment was wrong. As the recommended fix is omitting a trust manager, it makes sense for there only to be one code sample instead of two in the JCE case. For Android, this is different, so I think your fix makes sense here as well.

Copy link
Contributor

@egon-okerman-sonarsource egon-okerman-sonarsource left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, I suggested two changes for consistency with other security rules.

Copy link

Quality Gate passed Quality Gate passed for 'rspec-tools'

Issues
0 New issues
0 Fixed issues
0 Accepted issues

Measures
0 Security Hotspots
No data about Coverage
No data about Duplication

See analysis details on SonarQube

Copy link

Quality Gate passed Quality Gate passed for 'rspec-frontend'

Issues
0 New issues
0 Fixed issues
0 Accepted issues

Measures
0 Security Hotspots
No data about Coverage
No data about Duplication

See analysis details on SonarQube

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants