Skip to content

SONARPY-314 Rule S4790: Hashing data is security-sensitive#216

Merged
2 commits merged intomasterfrom
SONARPY-314
Mar 6, 2019
Merged

SONARPY-314 Rule S4790: Hashing data is security-sensitive#216
2 commits merged intomasterfrom
SONARPY-314

Conversation

@andrea-guarino-sonarsource
Copy link
Copy Markdown
Contributor

No description provided.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Why using an immutable Set to then stream on it?! Please use:

Stream.of("a", "b").map(...

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Same approach as before, no need for the intermediate ImmutableSet

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

and again.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Rather than chained if-else-ifI would prefer to have a switch:

switch(node.getType()) {
  case PythonGrammar.CALL_EXPR:
    checkQuestionableHashingAlgorithm(node);
    break;
  case /*...*/ :
    // ...
    break;
  default:
    // do nothing - reacting on all the registered nodes
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

this deserve a comment, otherwise I would tend to remove it.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

don't you want to explicitly return here?
It sounds strange to me that we could raise 2 issues in one run (by reaching both line 128 and 135), but if you think it's OK, then fine.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

yes indeed, I agree. I'll add a return

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

what if there is parenthesis?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

In case of parenthesis, TESTLIST_STAR_EXPR will still be the first child of EXPRESSION_STMT.
Parenthesis will be consumed lower in the grammar (in ATOM production rule) and at line 123 I'm taking the firstDescendant(PythonGrammar.ATTRIBUTE_REF).
I'm adding a test case to cover this.

However I just realized I won't raise an issue in this case:

foo.bar, mySettings.PASSWORD_HASHERS = value # Noncompliant

I will change my implementation to cover this case

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

should be annotated @CheckForNull

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

return symbol != null ? symbol.qualifiedName() : "";

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

.filter(atom -> questionableDjangoHashers.contains(getQualifiedName(atom)))
.forEach(atom -> addIssue(atom, MESSAGE));

@ghost ghost merged commit 664582c into master Mar 6, 2019
@ghost ghost deleted the SONARPY-314 branch March 6, 2019 12:59
hashicorp-vault-sonar-prod Bot pushed a commit that referenced this pull request Apr 24, 2025
…les execution (#216)

GitOrigin-RevId: c7c8ff947ad8efbb3f6d243ed1bf399ac64ba1b5
This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants