-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Swift: detect the use of constant salts #10993
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
Swift: detect the use of constant salts #10993
Conversation
QHelp previews: swift/ql/src/queries/Security/CWE-760/ConstantSalt.qhelpUse of constant saltsConstant salts should not be used for password hashing. Data hashed using constant salts are vulnerable to dictionary attacks, enabling attackers to recover the original input. RecommendationUse randomly generated salts to securely hash input data. ExampleThe following example shows a few cases of hashing input data. In the 'BAD' cases, the salt is constant, making the generated hashes vulnerable to dictionary attacks. In the 'GOOD' cases, the salt is randomly generated, which protects the hashed data against recovery.
References
|
exists(ClassOrStructDecl c, AbstractFunctionDecl f, CallExpr call, int arg | | ||
c.getFullName() = ["HKDF", "PBKDF1", "PBKDF2", "Scrypt"] and | ||
c.getAMember() = f and | ||
f.getName().matches("%init(%salt:%") and |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks like a great start, my only concern is how often salts are specified in the wild using the functions modelled above. I did a quick MRVA query for parameters called "salt" (or similar) and the most common call that appears to be relevant is to a thing called CCKeyDerivationPBKDF(_:_:_:_:_:_:_:_:_:)
from CommonCrypto
. Do you think we should perhaps create a follow-up issue to add a model of that to this query as well?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should add further support for CommonCrytpo
, not just for this query, but perhaps other crypto queries too. This might be a good first step in supporting more crypto APIs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would you mind creating an issue for that, listing the support you think we need to add?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done. Just added one with an initial set of tasks along with some useful resources.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Possible future expansions aside, I'm happy with this query. Ready for docs review?
👋 Docs first responder here! I've put this on our review board for a writer to review |
Thanks @lucascosti for adding this PR to your review board. I was wondering though if a team member will be able to pick it up this week for docs review? |
@karimhamdanali 👋🏻 - I've picked this up for editorial review and will review this for you today 😃 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@karimhamdanali 👋🏻 - this LGTM ✨
Left a few comments for your consideration.
1756fea
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Constant salts should not be used for password hashing. Data hashed using constant salts are vulnerable to dictionary attacks, enabling attackers to recover the original input.
The rule currently supports all ciphers that the CryptoSwift API provides, but we can always extend it further if more APIs are added.
I'd appreciate a review of the query itself, the accompanying tests, and the associated documentation.