Skip to content

Commit

Permalink
Scripts: Support for code and help links for script scan rules
Browse files Browse the repository at this point in the history
Signed-off-by: Simon Bennetts <[email protected]>
  • Loading branch information
psiinon committed May 2, 2024
1 parent 3085b54 commit 82803e1
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 1 deletion.
2 changes: 2 additions & 0 deletions addOns/commonlib/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## Unreleased
### Added
- Support for code and help links for script scan rules.
### Changed
- Maintenance changes.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ public class ScanRuleMetadata {
private Map<String, String> alertTags;
private String otherInfo;
private AddOn.Status status = AddOn.Status.unknown;
private String codeLink;
private String helpLink;

// Required for Jackson YAML deserialization
private ScanRuleMetadata() {}
Expand Down Expand Up @@ -168,6 +170,22 @@ public void setStatus(AddOn.Status status) {
this.status = status;
}

public String getCodeLink() {
return codeLink;
}

public void setCodeLink(String codeLink) {
this.codeLink = codeLink;
}

public String getHelpLink() {
return helpLink;
}

public void setHelpLink(String helpLink) {
this.helpLink = helpLink;
}

public static ScanRuleMetadata fromYaml(String yaml) {
ScanRuleMetadata metadata;
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,9 @@ void shouldParseMetadataYaml() {
+ " name1: value1\n"
+ " name2: value2\n"
+ "otherInfo: Any other Info\n"
+ "status: alpha";
+ "status: alpha"
+ "codeLink: https://www.example.com/codelink"
+ "helpLink: https://www.example.com/helplink";
// When
var metadata = ScanRuleMetadata.fromYaml(yaml);
// Then
Expand All @@ -78,6 +80,8 @@ void shouldParseMetadataYaml() {
metadata.getAlertTags(), is(equalTo(Map.of("name1", "value1", "name2", "value2"))));
assertThat(metadata.getOtherInfo(), is(equalTo("Any other Info")));
assertThat(metadata.getStatus(), is(equalTo(AddOn.Status.alpha)));
assertThat(metadata.getCodeLink(), is(equalTo("https://www.example.com/codelink")));
assertThat(metadata.getHelpLink(), is(equalTo("https://www.example.com/helplink")));
}

@Test
Expand Down
3 changes: 3 additions & 0 deletions addOns/scripts/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ All notable changes to this add-on will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).

## Unreleased
### Added
- Support for code and help links for script scan rules.

### Changed
- Allow to set raw parameter values from Active Rules, by calling `as.setEscapedParam(HttpMessage msg, String param, String value)`.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,14 @@ public boolean isEnabled() {
return script.isEnabled();
}

public String getCodeLink() {
return metadata.getCodeLink();
}

public String getHelpLink() {
return metadata.getHelpLink();
}

private ExtensionScript getExtScript() {
if (extScript == null) {
extScript =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,14 @@ public boolean isEnabled() {
return script.isEnabled();
}

public String getCodeLink() {
return metadata.getCodeLink();
}

public String getHelpLink() {
return metadata.getHelpLink();
}

@Override
public List<Alert> getExampleAlerts() {
return List.of(newAlert().build());
Expand Down

0 comments on commit 82803e1

Please sign in to comment.