Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ascanrules: add example alert to Cross Site Scripting (Persistent) #5660

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions addOns/ascanrules/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/).

## Unreleased

### Changed
- The Cross Site Scripting rule now includes example alert functionality for documentation generation purposes (Issue 6119)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

- The Cross Site Scripting (Persistent) scan rule…


## [67] - 2024-07-22

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -680,6 +680,29 @@ public void scan(HttpMessage sourceMsg, String param, String value) {
}
}

@Override
public List<Alert> getExampleAlerts() {
return List.of(
buildAlert(
"https://example.com/comments",
"comment",
"<script>alert('XSS');</script>",
'P',
"HTTP/1.1 500 Internal Server Error")
.build());
}

private AlertBuilder buildAlert(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The idea is to have the existing newAlert() calls to use this new method (adjusted as needed), to avoid duplication and ensure the example alerts match the raised alerts.

String url, String param, String attack, char type, String evidence) {
return newAlert()
.setConfidence(Alert.CONFIDENCE_HIGH)
.setUri(url)
.setParam(param)
.setAttack(attack)
.setOtherInfo(getError(type))
.setEvidence(evidence);
}

@Override
public int getRisk() {
return Alert.RISK_HIGH;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,10 @@
import static org.hamcrest.Matchers.is;

import java.util.Map;
import java.util.List;
import org.junit.jupiter.api.Test;
import org.zaproxy.addon.commonlib.CommonAlertTag;
import org.parosproxy.paros.core.scanner.Alert;

/** Unit test for {@link PersistentXssScanRule}. */
class PersistentXssScanRuleUnitTest extends ActiveScannerTest<PersistentXssScanRule> {
Expand Down Expand Up @@ -62,4 +64,16 @@ void shouldReturnExpectedMappings() {
tags.get(CommonAlertTag.WSTG_V42_INPV_02_STORED_XSS.getTag()),
is(equalTo(CommonAlertTag.WSTG_V42_INPV_02_STORED_XSS.getValue())));
}

@Test
void shouldHaveExpectedExampleAlert() {
List<Alert> alerts = rule.getExampleAlerts();
assertThat(alerts.size(), is(equalTo(1)));
}

@Test
@Override
public void shouldHaveValidReferences() {
super.shouldHaveValidReferences();
}
}
Loading