|
| 1 | +from codemodder.codemods.base_codemod import Metadata, ReviewGuidance, ToolRule |
| 2 | +from codemodder.codemods.libcst_transformer import ( |
| 3 | + LibcstResultTransformer, |
| 4 | + LibcstTransformerPipeline, |
| 5 | +) |
| 6 | +from codemodder.codetf import Reference |
| 7 | +from core_codemods.sonar.api import SonarCodemod |
| 8 | + |
| 9 | +rules = [ |
| 10 | + ToolRule( |
| 11 | + id="python:S5332", |
| 12 | + name="Using clear-text protocols is security-sensitive", |
| 13 | + url="https://rules.sonarsource.com/python/RSPEC-5332/", |
| 14 | + ), |
| 15 | +] |
| 16 | + |
| 17 | + |
| 18 | +class SonarUseSecureProtocolsTransformer(LibcstResultTransformer): |
| 19 | + change_description = "Modified URLs or calls to use secure protocols" |
| 20 | + |
| 21 | + def leave_Call(self, original_node, updated_node): |
| 22 | + return updated_node |
| 23 | + |
| 24 | + |
| 25 | +SonarUseSecureProtocols = SonarCodemod( |
| 26 | + metadata=Metadata( |
| 27 | + name="use-secure-protocols", |
| 28 | + summary="Use encrypted protocols instead of clear-text", |
| 29 | + review_guidance=ReviewGuidance.MERGE_AFTER_CURSORY_REVIEW, |
| 30 | + references=[ |
| 31 | + Reference( |
| 32 | + url="https://docs.python.org/3/library/ftplib.html#ftplib.FTP_TLS" |
| 33 | + ), |
| 34 | + Reference( |
| 35 | + url="https://docs.python.org/3/library/smtplib.html#smtplib.SMTP.starttls" |
| 36 | + ), |
| 37 | + Reference(url="https://owasp.org/Top10/A02_2021-Cryptographic_Failures/"), |
| 38 | + Reference( |
| 39 | + url="https://owasp.org/www-project-top-ten/2017/A3_2017-Sensitive_Data_Exposure" |
| 40 | + ), |
| 41 | + Reference(url="https://cwe.mitre.org/data/definitions/200"), |
| 42 | + Reference(url="https://cwe.mitre.org/data/definitions/319"), |
| 43 | + ], |
| 44 | + ), |
| 45 | + transformer=LibcstTransformerPipeline(SonarUseSecureProtocolsTransformer), |
| 46 | + default_extensions=[".py"], |
| 47 | + requested_rules=[tr.id for tr in rules], |
| 48 | +) |
0 commit comments