-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
NEW: @W-17310939@: Add in our first AppExchange security rule to serv…
…e as a template for adding in more
- Loading branch information
1 parent
f18af25
commit 5abdae6
Showing
9 changed files
with
144 additions
and
16 deletions.
There are no files selected for viewing
27 changes: 27 additions & 0 deletions
27
...s/code-analyzer-pmd-engine/pmd-rules/src/main/resources/sfca/rulesets/AppExchange_xml.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<ruleset name="AppExchange" | ||
xmlns="http://pmd.sourceforge.net/ruleset/2.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://pmd.sourceforge.net/ruleset/2.0.0 https://pmd.sourceforge.io/ruleset_2_0_0.xsd"> | ||
<description>AppExchange Security Rules</description> | ||
|
||
<rule name="AvoidInsecureHttpRemoteSiteSetting" | ||
language="xml" | ||
class="net.sourceforge.pmd.lang.rule.xpath.XPathRule" | ||
message="Avoid using insecure http urls in Remote Site Settings."> | ||
<!-- TODO: NEED TO ADD IN externalInfoUrl ONCE WE HAVE A PERMANENT LOCATION FOR THE DOC PAGE --> | ||
<description>Detects instances of a Remote Site Settings that use HTTP.Use HTTPS instead.</description> | ||
<priority>3</priority> | ||
<properties> | ||
<property name="xpath"> | ||
<value> | ||
<![CDATA[ | ||
/document/RemoteSiteSetting/url/text[starts-with(lower-case(@Text),"http://")] | ||
]]> | ||
</value> | ||
</property> | ||
</properties> | ||
</rule> | ||
|
||
|
||
</ruleset> |
16 changes: 16 additions & 0 deletions
16
...s/src/test/java/sfca/rulesets/appexchange_xml/AvoidInsecureHttpRemoteSiteSettingTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package sfca.rulesets.appexchange_xml; | ||
|
||
import net.sourceforge.pmd.test.SimpleAggregatorTst; | ||
|
||
public class AvoidInsecureHttpRemoteSiteSettingTest extends SimpleAggregatorTst { | ||
@Override | ||
protected void setUp() { | ||
// The test data xml file for this rule's test will always be in the resources directory using a naming | ||
// convention based off the package for this test and the rule being tested: | ||
// "resources/<TestPackageName>/xml/<RuleName>.xml". | ||
// In this case "sfca.rulesets.appexchange_xml" is the package name of this test file. Thus, the associated test | ||
// data xml file for this rule must be found at: | ||
// "resource/sfca/rulesets/appexchange_xml/xml/AvoidInsecureHttpRemoteSiteSetting.xml" | ||
addRule("sfca/rulesets/AppExchange_xml.xml", "AvoidInsecureHttpRemoteSiteSetting"); | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
...c/test/resources/sfca/rulesets/appexchange_xml/xml/AvoidInsecureHttpRemoteSiteSetting.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<test-data | ||
xmlns="http://pmd.sourceforge.net/rule-tests" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://pmd.sourceforge.net/rule-tests https://pmd.sourceforge.net/rule-tests_1_0_0.xsd"> | ||
|
||
<test-code> | ||
<description>When url contains http then violation should be reported</description> | ||
<expected-problems>1</expected-problems> | ||
<expected-linenumbers>6</expected-linenumbers> | ||
<expected-messages> | ||
<message>Avoid using insecure http urls in Remote Site Settings.</message> | ||
</expected-messages> | ||
<code><![CDATA[ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<RemoteSiteSetting xmlns="http://soap.sforce.com/2006/04/metadata"> | ||
<description>Used for Apex callout to mapping web service</description> | ||
<disableProtocolSecurity>false</disableProtocolSecurity> | ||
<isActive>true</isActive> | ||
<url>http://www.maptestsite.net/mapping1</url> | ||
</RemoteSiteSetting> | ||
]]></code> | ||
</test-code> | ||
|
||
<test-code> | ||
<description>When url contains https then violation should not be reported</description> | ||
<expected-problems>0</expected-problems> | ||
<code><![CDATA[ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<RemoteSiteSetting xmlns="http://soap.sforce.com/2006/04/metadata"> | ||
<description>Used for Apex callout to mapping web service</description> | ||
<disableProtocolSecurity>false</disableProtocolSecurity> | ||
<isActive>true</isActive> | ||
<url>https://www.maptestsite.net/mapping1</url> | ||
</RemoteSiteSetting> | ||
]]></code> | ||
</test-code> | ||
|
||
</test-data> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters