Skip to content

Commit

Permalink
Merge pull request #5960 from kingthorin/add-tags-50k
Browse files Browse the repository at this point in the history
scripts: Add Policy Tags to ScriptsActiveScanner
  • Loading branch information
thc202 authored Nov 28, 2024
2 parents 6601642 + 0a32fe9 commit 5d84d31
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 1 deletion.
2 changes: 2 additions & 0 deletions addOns/scripts/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
## Unreleased
### Added
- Report indirect script errors while the Automation Framework plans are running (Issue 8586).
- Standardized Policy Tags to the base Scripts Active Scanner.

### Changed
- Fields with default or missing values are omitted for the `script` job in saved Automation Framework plans.
- Depends on an updated version of the Common Library add-on.

## [45.7.0] - 2024-10-07
### Fixed
Expand Down
2 changes: 1 addition & 1 deletion addOns/scripts/scripts.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ zapAddOn {
dependencies {
addOns {
register("commonlib") {
version.set(">=1.25.0")
version.set(">=1.29.0")
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,18 @@
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.parosproxy.paros.Constant;
import org.parosproxy.paros.control.Control;
import org.parosproxy.paros.core.scanner.Alert;
import org.parosproxy.paros.core.scanner.Category;
import org.parosproxy.paros.network.HttpMessage;
import org.zaproxy.addon.commonlib.PolicyTag;
import org.zaproxy.addon.commonlib.scanrules.ScanRuleMetadataProvider;
import org.zaproxy.zap.extension.ascan.ExtensionActiveScan;
import org.zaproxy.zap.extension.script.ExtensionScript;
Expand All @@ -45,6 +49,9 @@ public class ScriptsActiveScanner extends ActiveScriptHelper {
private ScriptsCache<ActiveScript> cachedScripts;

private static final Logger LOGGER = LogManager.getLogger(ScriptsActiveScanner.class);
private static final Map<String, String> POLICY_ALERT_TAGS =
Stream.of(PolicyTag.values())
.collect(Collectors.toUnmodifiableMap(k -> k.getTag(), v -> ""));

/**
* A {@code Set} containing the scripts that do not implement {@code ActiveScript2}, to show an
Expand Down Expand Up @@ -252,4 +259,9 @@ public int getCweId() {
public int getWascId() {
return 0;
}

@Override
public Map<String, String> getAlertTags() {
return POLICY_ALERT_TAGS;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
import org.parosproxy.paros.model.Model;
import org.parosproxy.paros.network.HttpMessage;
import org.parosproxy.paros.network.HttpRequestHeader;
import org.zaproxy.addon.commonlib.PolicyTag;
import org.zaproxy.addon.commonlib.scanrules.ScanRuleMetadataProvider;
import org.zaproxy.zap.extension.ascan.ExtensionActiveScan;
import org.zaproxy.zap.extension.ascan.VariantFactory;
Expand Down Expand Up @@ -431,6 +432,16 @@ void shouldHandleExceptionsThrownByActiveScript() throws Exception {
verify(script2, times(1)).scan(scriptsActiveScanner, message, name2, value2);
}

@Test
void shouldHaveExpectedNumberOfAlertTags() {
// Given
ScriptsActiveScanner scriptsActiveScanner = new ScriptsActiveScanner();
// When
int tagCount = scriptsActiveScanner.getAlertTags().size();
// Then
assertThat(tagCount, is(equalTo(PolicyTag.values().length)));
}

private <T> ScriptWrapper createScriptWrapper(T script, Class<T> scriptClass) throws Exception {
ScriptWrapper scriptWrapper = mock(ScriptWrapper.class);
given(scriptWrapper.isEnabled()).willReturn(true);
Expand Down

0 comments on commit 5d84d31

Please sign in to comment.