diff --git a/internal/services/engines/dart/rules.go b/internal/services/engines/dart/rules.go index 460e91ab7..98dfed090 100644 --- a/internal/services/engines/dart/rules.go +++ b/internal/services/engines/dart/rules.go @@ -28,11 +28,13 @@ import ( func NewUsageLocalDataWithoutCryptography() *text.Rule { return &text.Rule{ Metadata: engine.Metadata{ - ID: "HS-DART-1", - Name: "Usage Local Data Without Cryptography", - Description: "While useful to speed applications up on the client side, it can be dangerous to store sensitive information this way because the data is not encrypted by default and any script on the page may access it. This rule raises an issue when the SharedPreferences and localstorage API's are used. For more information checkout the OWSAP A3:2017 (https://owasp.org/www-project-top-ten/2017/A3_2017-Sensitive_Data_Exposure.html) advisory.", - Severity: severities.Info.ToString(), - Confidence: confidence.Low.ToString(), + ID: "HS-DART-1", + Name: "Usage Local Data Without Cryptography", + Description: "While useful to speed applications up on the client side, it can be dangerous to store sensitive information this way because the data is not encrypted by default and any script on the page may access it. This rule raises an issue when the SharedPreferences and localstorage API's are used. For more information checkout the OWSAP A3:2017 (https://owasp.org/www-project-top-ten/2017/A3_2017-Sensitive_Data_Exposure.html) advisory.", + Severity: severities.Info.ToString(), + Confidence: confidence.Low.ToString(), + SafeExample: SampleSafeHSDART1, + UnsafeExample: SampleVulnerableHSDART1, }, Type: text.AndMatch, Expressions: []*regexp.Regexp{ @@ -45,11 +47,13 @@ func NewUsageLocalDataWithoutCryptography() *text.Rule { func NewNoSendSensitiveInformation() *text.Rule { return &text.Rule{ Metadata: engine.Metadata{ - ID: "HS-DART-2", - Name: "No Send Sensitive Information in alternative channels (sms, mms, notifications)", - Description: "Sensitive information should never send for this channels sms, mms, notifications. For more information checkout the CWE-532 (https://cwe.mitre.org/data/definitions/532.html) advisory.", - Severity: severities.Info.ToString(), - Confidence: confidence.Low.ToString(), + ID: "HS-DART-2", + Name: "No Send Sensitive Information in alternative channels (sms, mms, notifications)", + Description: "Sensitive information should never send for this channels sms, mms, notifications. For more information checkout the CWE-532 (https://cwe.mitre.org/data/definitions/532.html) advisory.", + Severity: severities.Info.ToString(), + Confidence: confidence.Low.ToString(), + SafeExample: SampleSafeHSDART2, + UnsafeExample: SampleVulnerableHSDART2, }, Type: text.AndMatch, Expressions: []*regexp.Regexp{ @@ -83,11 +87,13 @@ For more information checkout the OWSAP M4:2016 (https://owasp.org/www-project-m func NewXmlReaderExternalEntityExpansion() *text.Rule { return &text.Rule{ Metadata: engine.Metadata{ - ID: "HS-DART-4", - Name: "Xml Reader External Entity Expansion", - Description: "XML External Entity (XXE) vulnerabilities occur when applications process untrusted XML data without disabling external entities and DTD processing. Processing untrusted XML data with a vulnerable parser can allow attackers to extract data from the server, perform denial of service attacks, and in some cases gain remote code execution. The XmlReaderSettings and XmlTextReader classes are vulnerable to XXE attacks when setting the DtdProcessing property to DtdProcessing.Parse or the ProhibitDtd property to false. To prevent XmlReader XXE attacks, avoid using the deprecated ProhibitDtd property. Set the DtdProcessing property to DtdProcessing.Prohibit. For more information checkout the CWE-611 (https://cwe.mitre.org/data/definitions/611.html) advisory.", - Severity: severities.High.ToString(), - Confidence: confidence.High.ToString(), + ID: "HS-DART-4", + Name: "Xml Reader External Entity Expansion", + Description: "XML External Entity (XXE) vulnerabilities occur when applications process untrusted XML data without disabling external entities and DTD processing. Processing untrusted XML data with a vulnerable parser can allow attackers to extract data from the server, perform denial of service attacks, and in some cases gain remote code execution. The XmlReaderSettings and XmlTextReader classes are vulnerable to XXE attacks when setting the DtdProcessing property to DtdProcessing.Parse or the ProhibitDtd property to false. To prevent XmlReader XXE attacks, avoid using the deprecated ProhibitDtd property. Set the DtdProcessing property to DtdProcessing.Prohibit. For more information checkout the CWE-611 (https://cwe.mitre.org/data/definitions/611.html) advisory.", + Severity: severities.High.ToString(), + Confidence: confidence.High.ToString(), + SafeExample: SampleSafeHSDART4, + UnsafeExample: SampleVulnerableHSDART4, }, Type: text.AndMatch, Expressions: []*regexp.Regexp{ @@ -101,11 +107,13 @@ func NewXmlReaderExternalEntityExpansion() *text.Rule { func NewNoUseConnectionWithoutSSL() *text.Rule { return &text.Rule{ Metadata: engine.Metadata{ - ID: "HS-DART-5", - Name: "No use connection without SSL", - Description: "Insecure Implementation of SSL. Trusting all the certificates or accepting self signed certificates is a critical Security Hole. This application is vulnerable to MITM attacks. For more information checkout the CWE-295 (https://cwe.mitre.org/data/definitions/295.html) advisory.", - Severity: severities.High.ToString(), - Confidence: confidence.Medium.ToString(), + ID: "HS-DART-5", + Name: "No use connection without SSL", + Description: "Insecure Implementation of SSL. Trusting all the certificates or accepting self signed certificates is a critical Security Hole. This application is vulnerable to MITM attacks. For more information checkout the CWE-295 (https://cwe.mitre.org/data/definitions/295.html) advisory.", + Severity: severities.High.ToString(), + Confidence: confidence.Medium.ToString(), + SafeExample: SampleSafeHSDART5, + UnsafeExample: SampleVulnerableHSDART5, }, Type: text.OrMatch, Expressions: []*regexp.Regexp{ @@ -119,11 +127,13 @@ func NewNoUseConnectionWithoutSSL() *text.Rule { func NewSendSMS() *text.Rule { return &text.Rule{ Metadata: engine.Metadata{ - ID: "HS-DART-6", - Name: "Send SMS", - Description: "Send SMS. For more information checkout the OWASP-M3 (https://owasp.org/www-project-mobile-top-10/2016-risks/m3-insecure-communication) advisory", - Severity: severities.Low.ToString(), - Confidence: confidence.Low.ToString(), + ID: "HS-DART-6", + Name: "Send SMS", + Description: "Send SMS. For more information checkout the OWASP-M3 (https://owasp.org/www-project-mobile-top-10/2016-risks/m3-insecure-communication) advisory", + Severity: severities.Low.ToString(), + Confidence: confidence.Low.ToString(), + SafeExample: SampleSafeHSDART6, + UnsafeExample: SampleVulnerableHSDART6, }, Type: text.OrMatch, Expressions: []*regexp.Regexp{ @@ -136,11 +146,13 @@ func NewSendSMS() *text.Rule { func NewXSSAttack() *text.Rule { return &text.Rule{ Metadata: engine.Metadata{ - ID: "HS-DART-7", - Name: "Prevent XSS Attack", - Description: "A potential Cross-Site Scripting (XSS) was found. The endpoint returns a variable from the client entry that has not been coded. Always encode untrusted input before output, regardless of validation or cleaning performed. For more information checkout the CWE-79 (https://cwe.mitre.org/data/definitions/79.html) advisory.", - Severity: severities.Medium.ToString(), - Confidence: confidence.Low.ToString(), + ID: "HS-DART-7", + Name: "Prevent XSS Attack", + Description: "A potential Cross-Site Scripting (XSS) was found. The endpoint returns a variable from the client entry that has not been coded. Always encode untrusted input before output, regardless of validation or cleaning performed. For more information checkout the CWE-79 (https://cwe.mitre.org/data/definitions/79.html) advisory.", + Severity: severities.Medium.ToString(), + Confidence: confidence.Low.ToString(), + SafeExample: SampleSafeHSDART7, + UnsafeExample: SampleVulnerableHSDART7, }, Type: text.Regular, Expressions: []*regexp.Regexp{ @@ -152,11 +164,13 @@ func NewXSSAttack() *text.Rule { func NewNoLogSensitive() *text.Rule { return &text.Rule{ Metadata: engine.Metadata{ - ID: "HS-DART-8", - Name: "No Log Sensitive Information in console", - Description: "The App logs information. Sensitive information should never be logged. For more information checkout the CWE-532 (https://cwe.mitre.org/data/definitions/532.html) advisory.", - Severity: severities.Info.ToString(), - Confidence: confidence.Low.ToString(), + ID: "HS-DART-8", + Name: "No Log Sensitive Information in console", + Description: "The App logs information. Sensitive information should never be logged. For more information checkout the CWE-532 (https://cwe.mitre.org/data/definitions/532.html) advisory.", + Severity: severities.Info.ToString(), + Confidence: confidence.Low.ToString(), + SafeExample: SampleSafeHSDART8, + UnsafeExample: SampleVulnerableHSDART8, }, Type: text.Regular, Expressions: []*regexp.Regexp{ @@ -170,11 +184,13 @@ func NewNoLogSensitive() *text.Rule { func NewWeakHashingFunctionMd5OrSha1() *text.Rule { return &text.Rule{ Metadata: engine.Metadata{ - ID: "HS-DART-9", - Name: "Weak hashing function md5 or sha1", - Description: "MD5 or SHA1 have known collision weaknesses and are no longer considered strong hashing algorithms. For more information checkout the CWE-326 (https://cwe.mitre.org/data/definitions/326.html) advisory.", - Severity: severities.Medium.ToString(), - Confidence: confidence.Medium.ToString(), + ID: "HS-DART-9", + Name: "Weak hashing function md5 or sha1", + Description: "MD5 or SHA1 have known collision weaknesses and are no longer considered strong hashing algorithms. For more information checkout the CWE-326 (https://cwe.mitre.org/data/definitions/326.html) advisory.", + Severity: severities.Medium.ToString(), + Confidence: confidence.Medium.ToString(), + SafeExample: SampleSafeHSDART9, + UnsafeExample: SampleVulnerableHSDART9, }, Type: text.Regular, Expressions: []*regexp.Regexp{ @@ -189,11 +205,13 @@ func NewWeakHashingFunctionMd5OrSha1() *text.Rule { func NewNoUseSelfSignedCertificate() *text.Rule { return &text.Rule{ Metadata: engine.Metadata{ - ID: "HS-DART-10", - Name: "No Use Self Signed Certificate", - Description: "Insecure Implementation of SSL. Trusting all the certificates or accepting self signed certificates is a critical Security Hole. This application is vulnerable to MITM attacks. For more information checkout the CWE-295 (https://cwe.mitre.org/data/definitions/295.html) advisory.", - Severity: severities.Critical.ToString(), - Confidence: confidence.High.ToString(), + ID: "HS-DART-10", + Name: "No Use Self Signed Certificate", + Description: "Insecure Implementation of SSL. Trusting all the certificates or accepting self signed certificates is a critical Security Hole. This application is vulnerable to MITM attacks. For more information checkout the CWE-295 (https://cwe.mitre.org/data/definitions/295.html) advisory.", + Severity: severities.Critical.ToString(), + Confidence: confidence.High.ToString(), + SafeExample: SampleSafeHSDART10, + UnsafeExample: SampleVulnerableHSDART10, }, Type: text.Regular, Expressions: []*regexp.Regexp{ @@ -206,11 +224,13 @@ func NewNoUseSelfSignedCertificate() *text.Rule { func NewNoUseBiometricsTypeAndroid() *text.Rule { return &text.Rule{ Metadata: engine.Metadata{ - ID: "HS-DART-11", - Name: "No use biometrics types face or fingerprint for login in account", - Description: "If the mobile app uses a feature like TouchID, it suffers from insecure authentication. For more information checkout the OWSAP M4:2016 (https://owasp.org/www-project-mobile-top-10/2016-risks/m4-insecure-authentication) advisory.", - Severity: severities.High.ToString(), - Confidence: confidence.Medium.ToString(), + ID: "HS-DART-11", + Name: "No use biometrics types face or fingerprint for login in account", + Description: "If the mobile app uses a feature like TouchID, it suffers from insecure authentication. For more information checkout the OWSAP M4:2016 (https://owasp.org/www-project-mobile-top-10/2016-risks/m4-insecure-authentication) advisory.", + Severity: severities.High.ToString(), + Confidence: confidence.Medium.ToString(), + SafeExample: SampleSafeHSDART11, + UnsafeExample: SampleVulnerableHSDART11, }, Type: text.Regular, Expressions: []*regexp.Regexp{ @@ -222,11 +242,13 @@ func NewNoUseBiometricsTypeAndroid() *text.Rule { func NewNoListClipboardChanges() *text.Rule { return &text.Rule{ Metadata: engine.Metadata{ - ID: "HS-DART-12", - Name: "No List changes on the clipboard", - Description: "The application allows you to list the changes on the Clipboard. Some malware also lists changes to the Clipboard.", - Severity: severities.Info.ToString(), - Confidence: confidence.High.ToString(), + ID: "HS-DART-12", + Name: "No List changes on the clipboard", + Description: "The application allows you to list the changes on the Clipboard. Some malware also lists changes to the Clipboard.", + Severity: severities.Info.ToString(), + Confidence: confidence.High.ToString(), + SafeExample: SampleSafeHSDART12, + UnsafeExample: SampleVulnerableHSDART12, }, Type: text.Regular, Expressions: []*regexp.Regexp{ @@ -238,11 +260,13 @@ func NewNoListClipboardChanges() *text.Rule { func NewSQLInjection() *text.Rule { return &text.Rule{ Metadata: engine.Metadata{ - ID: "HS-DART-13", - Name: "SQL Injection", - Description: "The input values included in SQL queries need to be passed in safely. Bind variables in prepared statements can be used to easily mitigate the risk of SQL injection. Alternatively to prepare statements, each parameter can be escaped manually. For more information checkout the CWE-89 (https://cwe.mitre.org/data/definitions/89.html) advisory.", - Severity: severities.High.ToString(), - Confidence: confidence.High.ToString(), + ID: "HS-DART-13", + Name: "SQL Injection", + Description: "The input values included in SQL queries need to be passed in safely. Bind variables in prepared statements can be used to easily mitigate the risk of SQL injection. Alternatively to prepare statements, each parameter can be escaped manually. For more information checkout the CWE-89 (https://cwe.mitre.org/data/definitions/89.html) advisory.", + Severity: severities.High.ToString(), + Confidence: confidence.High.ToString(), + SafeExample: SampleSafeHSDART13, + UnsafeExample: SampleVulnerableHSDART13, }, Type: text.Regular, Expressions: []*regexp.Regexp{ @@ -254,11 +278,13 @@ func NewSQLInjection() *text.Rule { func NewNoUseNSTemporaryDirectory() *text.Rule { return &text.Rule{ Metadata: engine.Metadata{ - ID: "HS-DART-14", - Name: "No use NSTemporaryDirectory", - Description: "User use in \"NSTemporaryDirectory ()\" is unreliable, it can result in vulnerabilities in the directory. For more information checkout the CWE-22 (https://cwe.mitre.org/data/definitions/22.html) advisory.", - Severity: severities.Info.ToString(), - Confidence: confidence.High.ToString(), + ID: "HS-DART-14", + Name: "No use NSTemporaryDirectory", + Description: "User use in \"NSTemporaryDirectory ()\" is unreliable, it can result in vulnerabilities in the directory. For more information checkout the CWE-22 (https://cwe.mitre.org/data/definitions/22.html) advisory.", + Severity: severities.Info.ToString(), + Confidence: confidence.High.ToString(), + SafeExample: SampleSafeHSDART14, + UnsafeExample: SampleVulnerableHSDART14, }, Type: text.Regular, Expressions: []*regexp.Regexp{ @@ -270,11 +296,13 @@ func NewNoUseNSTemporaryDirectory() *text.Rule { func NewNoUseCipherMode() *text.Rule { return &text.Rule{ Metadata: engine.Metadata{ - ID: "HS-DART-15", - Name: "No Use Cipher mode", - Description: "This mode is not recommended because it opens the door to various security exploits. If the plain text to be encrypted contains substantial repetitions, it is possible that the cipher text will be broken one block at a time. You can also use block analysis to determine the encryption key. In addition, an active opponent can replace and exchange individual blocks without detection, which allows the blocks to be saved and inserted into the stream at other points without detection. ECB and OFB mode will produce the same result for identical blocks. The use of AES in CBC mode with an HMAC is recommended, ensuring integrity and confidentiality. https://docs.microsoft.com/en-us/visualstudio/code-quality/ca5358?view=vs-2019. For more information checkout the CWE-326 (https://cwe.mitre.org/data/definitions/326.html) and CWE-327 (https://cwe.mitre.org/data/definitions/327.html) advisory.", - Severity: severities.Medium.ToString(), - Confidence: confidence.Medium.ToString(), + ID: "HS-DART-15", + Name: "No Use Cipher mode", + Description: "This mode is not recommended because it opens the door to various security exploits. If the plain text to be encrypted contains substantial repetitions, it is possible that the cipher text will be broken one block at a time. You can also use block analysis to determine the encryption key. In addition, an active opponent can replace and exchange individual blocks without detection, which allows the blocks to be saved and inserted into the stream at other points without detection. ECB and OFB mode will produce the same result for identical blocks. The use of AES in CBC mode with an HMAC is recommended, ensuring integrity and confidentiality. https://docs.microsoft.com/en-us/visualstudio/code-quality/ca5358?view=vs-2019. For more information checkout the CWE-326 (https://cwe.mitre.org/data/definitions/326.html) and CWE-327 (https://cwe.mitre.org/data/definitions/327.html) advisory.", + Severity: severities.Medium.ToString(), + Confidence: confidence.Medium.ToString(), + SafeExample: SampleSafeHSDART15, + UnsafeExample: SampleVulnerableHSDART15, }, Type: text.Regular, Expressions: []*regexp.Regexp{ @@ -289,11 +317,13 @@ func NewNoUseCipherMode() *text.Rule { func NewCorsAllowOriginWildCard() *text.Rule { return &text.Rule{ Metadata: engine.Metadata{ - ID: "HS-DART-16", - Name: "Cors Allow Origin Wild Card", - Description: "Cross-Origin Resource Sharing (CORS) allows a service to disable the browser’s Same-origin policy, which prevents scripts on an attacker-controlled domain from accessing resources and data hosted on a different domain. The CORS Access-Control-Allow-Origin HTTP header specifies the domain with permission to invoke a cross-origin service and view the response data. Configuring the Access-Control-Allow-Origin header with a wildcard (*) can allow code running on an attacker-controlled domain to view responses containing sensitive data. For more information checkout the CWE-942 (https://cwe.mitre.org/data/definitions/942.html) advisory.", - Severity: severities.Medium.ToString(), - Confidence: confidence.High.ToString(), + ID: "HS-DART-16", + Name: "Cors Allow Origin Wild Card", + Description: "Cross-Origin Resource Sharing (CORS) allows a service to disable the browser’s Same-origin policy, which prevents scripts on an attacker-controlled domain from accessing resources and data hosted on a different domain. The CORS Access-Control-Allow-Origin HTTP header specifies the domain with permission to invoke a cross-origin service and view the response data. Configuring the Access-Control-Allow-Origin header with a wildcard (*) can allow code running on an attacker-controlled domain to view responses containing sensitive data. For more information checkout the CWE-942 (https://cwe.mitre.org/data/definitions/942.html) advisory.", + Severity: severities.Medium.ToString(), + Confidence: confidence.High.ToString(), + SafeExample: SampleSafeHSDART16, + UnsafeExample: SampleVulnerableHSDART16, }, Type: text.Regular, Expressions: []*regexp.Regexp{ @@ -305,11 +335,13 @@ func NewCorsAllowOriginWildCard() *text.Rule { func NewUsingShellInterpreterWhenExecutingOSCommand() *text.Rule { return &text.Rule{ Metadata: engine.Metadata{ - ID: "HS-DART-17", - Name: "Using shell interpreter when executing OS commands", - Description: "Arbitrary OS command injection vulnerabilities are more likely when a shell is spawned rather than a new process, indeed shell meta-chars can be used (when parameters are user-controlled for instance) to inject OS commands. For more information checkout the CWE-78 (https://cwe.mitre.org/data/definitions/78.html) advisory.", - Severity: severities.Medium.ToString(), - Confidence: confidence.High.ToString(), + ID: "HS-DART-17", + Name: "Using shell interpreter when executing OS commands", + Description: "Arbitrary OS command injection vulnerabilities are more likely when a shell is spawned rather than a new process, indeed shell meta-chars can be used (when parameters are user-controlled for instance) to inject OS commands. For more information checkout the CWE-78 (https://cwe.mitre.org/data/definitions/78.html) advisory.", + Severity: severities.Medium.ToString(), + Confidence: confidence.High.ToString(), + SafeExample: SampleSafeHSDART17, + UnsafeExample: SampleVulnerableHSDART17, }, Type: text.Regular, Expressions: []*regexp.Regexp{ diff --git a/internal/services/engines/dart/rules_test.go b/internal/services/engines/dart/rules_test.go index 35d78206b..f45c8b61b 100644 --- a/internal/services/engines/dart/rules_test.go +++ b/internal/services/engines/dart/rules_test.go @@ -15,7 +15,6 @@ package dart import ( - "fmt" "path/filepath" "testing" @@ -31,12 +30,12 @@ func TestRulesVulnerableCode(t *testing.T) { Name: "HS-DART-1", Rule: NewUsageLocalDataWithoutCryptography(), Src: SampleVulnerableHSDART1, - Filename: filepath.Join(tempDir, fmt.Sprintf("%s%s", "HS-DART-1", ".test")), + Filename: filepath.Join(tempDir, "HS-DART-1.test"), Findings: []engine.Finding{ { CodeSample: "SharedPreferences prefs = await SharedPreferences.getInstance();", SourceLocation: engine.Location{ - Filename: filepath.Join(tempDir, fmt.Sprintf("%s%s", "HS-DART-1", ".test")), + Filename: filepath.Join(tempDir, "HS-DART-1.test"), Line: 8, Column: 34, }, @@ -47,12 +46,12 @@ func TestRulesVulnerableCode(t *testing.T) { Name: "HS-DART-2", Rule: NewNoSendSensitiveInformation(), Src: SampleVulnerableHSDART2, - Filename: filepath.Join(tempDir, fmt.Sprintf("%s%s", "HS-DART-2", ".test")), + Filename: filepath.Join(tempDir, "HS-DART-2.test"), Findings: []engine.Finding{ { CodeSample: "_firebaseMessaging.configure(", SourceLocation: engine.Location{ - Filename: filepath.Join(tempDir, fmt.Sprintf("%s%s", "HS-DART-2", ".test")), + Filename: filepath.Join(tempDir, "HS-DART-2.test"), Line: 9, Column: 5, }, @@ -63,12 +62,12 @@ func TestRulesVulnerableCode(t *testing.T) { Name: "HS-DART-3", Rule: NewNoUseBiometricsTypeIOS(), Src: SampleVulnerableHSDART3, - Filename: filepath.Join(tempDir, fmt.Sprintf("%s%s", "HS-DART-3", ".test")), + Filename: filepath.Join(tempDir, "HS-DART-3.test"), Findings: []engine.Finding{ { CodeSample: "await auth.getAvailableBiometrics();", SourceLocation: engine.Location{ - Filename: filepath.Join(tempDir, fmt.Sprintf("%s%s", "HS-DART-3", ".test")), + Filename: filepath.Join(tempDir, "HS-DART-3.test"), Line: 3, Column: 15, }, @@ -79,12 +78,12 @@ func TestRulesVulnerableCode(t *testing.T) { Name: "HS-DART-4", Rule: NewXmlReaderExternalEntityExpansion(), Src: SampleVulnerableHSDART4, - Filename: filepath.Join(tempDir, fmt.Sprintf("%s%s", "HS-DART-4", ".test")), + Filename: filepath.Join(tempDir, "HS-DART-4.test"), Findings: []engine.Finding{ { CodeSample: "final file = new File(FileFromUserInput);", SourceLocation: engine.Location{ - Filename: filepath.Join(tempDir, fmt.Sprintf("%s%s", "HS-DART-4", ".test")), + Filename: filepath.Join(tempDir, "HS-DART-4.test"), Line: 3, Column: 13, }, @@ -95,12 +94,12 @@ func TestRulesVulnerableCode(t *testing.T) { Name: "HS-DART-5", Rule: NewNoUseConnectionWithoutSSL(), Src: SampleVulnerableHSDART5, - Filename: filepath.Join(tempDir, fmt.Sprintf("%s%s", "HS-DART-5", ".test")), + Filename: filepath.Join(tempDir, "HS-DART-5.test"), Findings: []engine.Finding{ { CodeSample: "return _HttpServer.bindSecure('http://my-api.com.br', port, context, backlog, v6Only, requestClientCertificate, shared);", SourceLocation: engine.Location{ - Filename: filepath.Join(tempDir, fmt.Sprintf("%s%s", "HS-DART-5", ".test")), + Filename: filepath.Join(tempDir, "HS-DART-5.test"), Line: 12, Column: 22, }, @@ -111,12 +110,12 @@ func TestRulesVulnerableCode(t *testing.T) { Name: "HS-DART-6", Rule: NewSendSMS(), Src: SampleVulnerableHSDART6, - Filename: filepath.Join(tempDir, fmt.Sprintf("%s%s", "HS-DART-6", ".test")), + Filename: filepath.Join(tempDir, "HS-DART-6.test"), Findings: []engine.Finding{ { CodeSample: "import 'package:flutter_sms/flutter_sms.dart';", SourceLocation: engine.Location{ - Filename: filepath.Join(tempDir, fmt.Sprintf("%s%s", "HS-DART-6", ".test")), + Filename: filepath.Join(tempDir, "HS-DART-6.test"), Line: 1, Column: 28, }, @@ -127,12 +126,12 @@ func TestRulesVulnerableCode(t *testing.T) { Name: "HS-DART-7", Rule: NewXSSAttack(), Src: SampleVulnerableHSDART7, - Filename: filepath.Join(tempDir, fmt.Sprintf("%s%s", "HS-DART-7", ".test")), + Filename: filepath.Join(tempDir, "HS-DART-7.test"), Findings: []engine.Finding{ { CodeSample: "var element = new Element.html(sprintf(\"
%s
\", [content]));", SourceLocation: engine.Location{ - Filename: filepath.Join(tempDir, fmt.Sprintf("%s%s", "HS-DART-7", ".test")), + Filename: filepath.Join(tempDir, "HS-DART-7.test"), Line: 8, Column: 19, }, @@ -143,12 +142,12 @@ func TestRulesVulnerableCode(t *testing.T) { Name: "HS-DART-8", Rule: NewNoLogSensitive(), Src: SampleVulnerableHSDART8, - Filename: filepath.Join(tempDir, fmt.Sprintf("%s%s", "HS-DART-8", ".test")), + Filename: filepath.Join(tempDir, "HS-DART-8.test"), Findings: []engine.Finding{ { CodeSample: "print(sprintf(\"User identity is: %s\", [identity]));", SourceLocation: engine.Location{ - Filename: filepath.Join(tempDir, fmt.Sprintf("%s%s", "HS-DART-8", ".test")), + Filename: filepath.Join(tempDir, "HS-DART-8.test"), Line: 9, Column: 1, }, @@ -156,7 +155,7 @@ func TestRulesVulnerableCode(t *testing.T) { { CodeSample: "_logger.info(sprintf(\"User identity is: %s\", [identity]));", SourceLocation: engine.Location{ - Filename: filepath.Join(tempDir, fmt.Sprintf("%s%s", "HS-DART-8", ".test")), + Filename: filepath.Join(tempDir, "HS-DART-8.test"), Line: 11, Column: 2, }, @@ -167,12 +166,12 @@ func TestRulesVulnerableCode(t *testing.T) { Name: "HS-DART-9", Rule: NewWeakHashingFunctionMd5OrSha1(), Src: SampleVulnerableHSDART9, - Filename: filepath.Join(tempDir, fmt.Sprintf("%s%s", "HS-DART-9", ".test")), + Filename: filepath.Join(tempDir, "HS-DART-9.test"), Findings: []engine.Finding{ { CodeSample: "var digest = md5.convert(content);", SourceLocation: engine.Location{ - Filename: filepath.Join(tempDir, fmt.Sprintf("%s%s", "HS-DART-9", ".test")), + Filename: filepath.Join(tempDir, "HS-DART-9.test"), Line: 11, Column: 15, }, @@ -183,12 +182,12 @@ func TestRulesVulnerableCode(t *testing.T) { Name: "HS-DART-10", Rule: NewNoUseSelfSignedCertificate(), Src: SampleVulnerableHSDART10, - Filename: filepath.Join(tempDir, fmt.Sprintf("%s%s", "HS-DART-10", ".test")), + Filename: filepath.Join(tempDir, "HS-DART-10.test"), Findings: []engine.Finding{ { CodeSample: "context.setTrustedCertificates(\"client.cer\");", SourceLocation: engine.Location{ - Filename: filepath.Join(tempDir, fmt.Sprintf("%s%s", "HS-DART-10", ".test")), + Filename: filepath.Join(tempDir, "HS-DART-10.test"), Line: 4, Column: 8, }, @@ -199,12 +198,12 @@ func TestRulesVulnerableCode(t *testing.T) { Name: "HS-DART-11", Rule: NewNoUseBiometricsTypeAndroid(), Src: SampleVulnerableHSDART11, - Filename: filepath.Join(tempDir, fmt.Sprintf("%s%s", "HS-DART-11", ".test")), + Filename: filepath.Join(tempDir, "HS-DART-11.test"), Findings: []engine.Finding{ { CodeSample: "authenticated = await auth.authenticateWithBiometrics(", SourceLocation: engine.Location{ - Filename: filepath.Join(tempDir, fmt.Sprintf("%s%s", "HS-DART-11", ".test")), + Filename: filepath.Join(tempDir, "HS-DART-11.test"), Line: 4, Column: 29, }, @@ -215,12 +214,12 @@ func TestRulesVulnerableCode(t *testing.T) { Name: "HS-DART-12", Rule: NewNoListClipboardChanges(), Src: SampleVulnerableHSDART12, - Filename: filepath.Join(tempDir, fmt.Sprintf("%s%s", "HS-DART-12", ".test")), + Filename: filepath.Join(tempDir, "HS-DART-12.test"), Findings: []engine.Finding{ { CodeSample: "Map result = await SystemChannels.platform.invokeMethod('Clipboard.getData');", SourceLocation: engine.Location{ - Filename: filepath.Join(tempDir, fmt.Sprintf("%s%s", "HS-DART-12", ".test")), + Filename: filepath.Join(tempDir, "HS-DART-12.test"), Line: 4, Column: 75, }, @@ -231,12 +230,12 @@ func TestRulesVulnerableCode(t *testing.T) { Name: "HS-DART-13", Rule: NewSQLInjection(), Src: SampleVulnerableHSDART13, - Filename: filepath.Join(tempDir, fmt.Sprintf("%s%s", "HS-DART-13", ".test")), + Filename: filepath.Join(tempDir, "HS-DART-13.test"), Findings: []engine.Finding{ { CodeSample: "List list = await database.rawQuery(\"SELECT * FROM Users WHERE username = '\" + username + \"';\");", SourceLocation: engine.Location{ - Filename: filepath.Join(tempDir, fmt.Sprintf("%s%s", "HS-DART-13", ".test")), + Filename: filepath.Join(tempDir, "HS-DART-13.test"), Line: 10, Column: 34, }, @@ -247,12 +246,12 @@ func TestRulesVulnerableCode(t *testing.T) { Name: "HS-DART-14", Rule: NewNoUseNSTemporaryDirectory(), Src: SampleVulnerableHSDART14, - Filename: filepath.Join(tempDir, fmt.Sprintf("%s%s", "HS-DART-14", ".test")), + Filename: filepath.Join(tempDir, "HS-DART-14.test"), Findings: []engine.Finding{ { CodeSample: "let temporaryDirectoryURL = URL(fileURLWithPath: NSTemporaryDirectory(), isDirectory: true);", SourceLocation: engine.Location{ - Filename: filepath.Join(tempDir, fmt.Sprintf("%s%s", "HS-DART-14", ".test")), + Filename: filepath.Join(tempDir, "HS-DART-14.test"), Line: 3, Column: 49, }, @@ -263,12 +262,12 @@ func TestRulesVulnerableCode(t *testing.T) { Name: "HS-DART-15", Rule: NewNoUseCipherMode(), Src: SampleVulnerableHSDART15, - Filename: filepath.Join(tempDir, fmt.Sprintf("%s%s", "HS-DART-15", ".test")), + Filename: filepath.Join(tempDir, "HS-DART-15.test"), Findings: []engine.Finding{ { CodeSample: "final encrypter = Encrypter(AES(key, mode: AESMode.cts));", SourceLocation: engine.Location{ - Filename: filepath.Join(tempDir, fmt.Sprintf("%s%s", "HS-DART-15", ".test")), + Filename: filepath.Join(tempDir, "HS-DART-15.test"), Line: 3, Column: 43, }, @@ -279,12 +278,12 @@ func TestRulesVulnerableCode(t *testing.T) { Name: "HS-DART-16", Rule: NewCorsAllowOriginWildCard(), Src: SampleVulnerableHSDART16, - Filename: filepath.Join(tempDir, fmt.Sprintf("%s%s", "HS-DART-16", ".test")), + Filename: filepath.Join(tempDir, "HS-DART-16.test"), Findings: []engine.Finding{ { CodeSample: `request.response.headers.add("Access-Control-Allow-Origin", "*");`, SourceLocation: engine.Location{ - Filename: filepath.Join(tempDir, fmt.Sprintf("%s%s", "HS-DART-16", ".test")), + Filename: filepath.Join(tempDir, "HS-DART-16.test"), Line: 9, Column: 32, }, @@ -295,12 +294,12 @@ func TestRulesVulnerableCode(t *testing.T) { Name: "HS-DART-17", Rule: NewUsingShellInterpreterWhenExecutingOSCommand(), Src: SampleVulnerableHSDART17, - Filename: filepath.Join(tempDir, fmt.Sprintf("%s%s", "HS-DART-17", ".test")), + Filename: filepath.Join(tempDir, "HS-DART-17.test"), Findings: []engine.Finding{ { CodeSample: `var result = await Process.run("netcfg", [UserParams]);`, SourceLocation: engine.Location{ - Filename: filepath.Join(tempDir, fmt.Sprintf("%s%s", "HS-DART-17", ".test")), + Filename: filepath.Join(tempDir, "HS-DART-17.test"), Line: 4, Column: 20, }, @@ -319,103 +318,103 @@ func TestRulesSafeCode(t *testing.T) { Name: "HS-DART-1", Rule: NewUsageLocalDataWithoutCryptography(), Src: SampleSafeHSDART1, - Filename: filepath.Join(tempDir, fmt.Sprintf("%s%s", "HS-DART-1", ".test")), + Filename: filepath.Join(tempDir, "HS-DART-1.test"), }, { Name: "HS-DART-2", Rule: NewNoSendSensitiveInformation(), Src: SampleSafeHSDART2, - Filename: filepath.Join(tempDir, fmt.Sprintf("%s%s", "HS-DART-2", ".test")), + Filename: filepath.Join(tempDir, "HS-DART-2.test"), }, { Name: "HS-DART-3", Rule: NewNoUseBiometricsTypeIOS(), Src: "", - Filename: filepath.Join(tempDir, fmt.Sprintf("%s%s", "HS-DART-3", ".test")), + Filename: filepath.Join(tempDir, "HS-DART-3.test"), }, { Name: "HS-DART-4", Rule: NewXmlReaderExternalEntityExpansion(), Src: SampleSafeHSDART4, - Filename: filepath.Join(tempDir, fmt.Sprintf("%s%s", "HS-DART-4", ".test")), + Filename: filepath.Join(tempDir, "HS-DART-4.test"), }, { Name: "HS-DART-5", Rule: NewNoUseConnectionWithoutSSL(), Src: SampleSafeHSDART5, - Filename: filepath.Join(tempDir, fmt.Sprintf("%s%s", "HS-DART-5", ".test")), + Filename: filepath.Join(tempDir, "HS-DART-5.test"), }, { Name: "HS-DART-6", Rule: NewSendSMS(), - Src: "", - Filename: filepath.Join(tempDir, fmt.Sprintf("%s%s", "HS-DART-6", ".test")), + Src: SampleSafeHSDART6, + Filename: filepath.Join(tempDir, "HS-DART-6.test"), }, { Name: "HS-DART-7", Rule: NewXSSAttack(), Src: SampleSafeHSDART7, - Filename: filepath.Join(tempDir, fmt.Sprintf("%s%s", "HS-DART-7", ".test")), + Filename: filepath.Join(tempDir, "HS-DART-7.test"), }, { Name: "HS-DART-8", Rule: NewNoLogSensitive(), Src: SampleSafeHSDART8, - Filename: filepath.Join(tempDir, fmt.Sprintf("%s%s", "HS-DART-8", ".test")), + Filename: filepath.Join(tempDir, "HS-DART-8.test"), }, { Name: "HS-DART-9", Rule: NewWeakHashingFunctionMd5OrSha1(), Src: SampleSafeHSDART9, - Filename: filepath.Join(tempDir, fmt.Sprintf("%s%s", "HS-DART-9", ".test")), + Filename: filepath.Join(tempDir, "HS-DART-9.test"), }, { Name: "HS-DART-10", Rule: NewNoUseSelfSignedCertificate(), Src: SampleSafeHSDART10, - Filename: filepath.Join(tempDir, fmt.Sprintf("%s%s", "HS-DART-10", ".test")), + Filename: filepath.Join(tempDir, "HS-DART-10.test"), }, { Name: "HS-DART-11", Rule: NewNoUseBiometricsTypeAndroid(), Src: SampleSafeHSDART11, - Filename: filepath.Join(tempDir, fmt.Sprintf("%s%s", "HS-DART-11", ".test")), + Filename: filepath.Join(tempDir, "HS-DART-11.test"), }, { Name: "HS-DART-12", Rule: NewNoListClipboardChanges(), Src: SampleSafeHSDART12, - Filename: filepath.Join(tempDir, fmt.Sprintf("%s%s", "HS-DART-12", ".test")), + Filename: filepath.Join(tempDir, "HS-DART-12.test"), }, { Name: "HS-DART-13", Rule: NewSQLInjection(), Src: SampleSafeHSDART13, - Filename: filepath.Join(tempDir, fmt.Sprintf("%s%s", "HS-DART-13", ".test")), + Filename: filepath.Join(tempDir, "HS-DART-13.test"), }, { Name: "HS-DART-14", Rule: NewNoUseNSTemporaryDirectory(), Src: SampleSafeHSDART14, - Filename: filepath.Join(tempDir, fmt.Sprintf("%s%s", "HS-DART-14", ".test")), + Filename: filepath.Join(tempDir, "HS-DART-14.test"), }, { Name: "HS-DART-15", Rule: NewNoUseCipherMode(), Src: SampleSafeHSDART15, - Filename: filepath.Join(tempDir, fmt.Sprintf("%s%s", "HS-DART-15", ".test")), + Filename: filepath.Join(tempDir, "HS-DART-15.test"), }, { Name: "HS-DART-16", Rule: NewCorsAllowOriginWildCard(), Src: SampleSafeHSDART16, - Filename: filepath.Join(tempDir, fmt.Sprintf("%s%s", "HS-DART-16", ".test")), + Filename: filepath.Join(tempDir, "HS-DART-16.test"), }, { Name: "HS-DART-17", Rule: NewUsingShellInterpreterWhenExecutingOSCommand(), Src: SampleSafeHSDART17, - Filename: filepath.Join(tempDir, fmt.Sprintf("%s%s", "HS-DART-17", ".test")), + Filename: filepath.Join(tempDir, "HS-DART-17.test"), }, } diff --git a/internal/services/engines/dart/sample_test.go b/internal/services/engines/dart/sample.go similarity index 99% rename from internal/services/engines/dart/sample_test.go rename to internal/services/engines/dart/sample.go index e08003e37..832087ad5 100644 --- a/internal/services/engines/dart/sample_test.go +++ b/internal/services/engines/dart/sample.go @@ -272,6 +272,7 @@ static Future SentToApi( bool shared = false} ) => _HttpServer.bindSecure('https://my-api.com.br', port, context, backlog, v6Only, requestClientCertificate, shared); ` + SampleSafeHSDART6 = `// You can't use sms library` SampleSafeHSDART7 = ` import 'package:sprintf/sprintf.dart'; import 'dart:html';