Skip to content

Commit

Permalink
Merge pull request #5634 from thc202/alertFilters/handle-deletion
Browse files Browse the repository at this point in the history
alertFilters: handle deleted alerts
  • Loading branch information
kingthorin authored Aug 8, 2024
2 parents 0b1413a + 8af0640 commit b24a40e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 31 deletions.
3 changes: 2 additions & 1 deletion addOns/alertFilters/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ 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

### Fixed
- Handle deleted alerts gracefully.

## [21] - 2024-05-07
### Changed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
import org.parosproxy.paros.control.Control;
import org.parosproxy.paros.control.Control.Mode;
import org.parosproxy.paros.core.scanner.Alert;
import org.parosproxy.paros.db.DatabaseException;
import org.parosproxy.paros.db.RecordAlert;
import org.parosproxy.paros.db.TableAlert;
import org.parosproxy.paros.extension.ExtensionAdaptor;
Expand Down Expand Up @@ -94,7 +93,6 @@ public class ExtensionAlertFilters extends ExtensionAdaptor
private ExtensionAlert extAlert = null;
private ExtensionHistory extHistory = null;
private AlertFilterAPI api = null;
private int lastAlert = -1;

private static ScanRulesInfo scanRulesInfo;
private static ExtensionActiveScan extAscan;
Expand Down Expand Up @@ -362,31 +360,14 @@ public void eventReceived(Event event) {
TableAlert tableAlert = Model.getSingleton().getDb().getTableAlert();

String alertId = event.getParameters().get(AlertEventPublisher.ALERT_ID);
if (alertId != null) {
// From 2.4.3 an alertId is included with these events, which makes life much simpler!
try {
handleAlert(tableAlert.read(Integer.parseInt(alertId)));
} catch (Exception e) {
LOGGER.error("Error handling alert", e);
}
} else {
// Required for pre 2.4.3 versions
RecordAlert recordAlert;
while (true) {
try {
this.lastAlert++;
recordAlert = tableAlert.read(this.lastAlert);
if (recordAlert == null) {
break;
}
handleAlert(recordAlert);

} catch (DatabaseException e) {
break;
}
try {
RecordAlert rc = tableAlert.read(Integer.parseInt(alertId));
if (rc == null) {
return;
}
// The loop will always go 1 further than necessary
this.lastAlert--;
handleAlert(rc);
} catch (Exception e) {
LOGGER.error("Error handling alert", e);
}
}

Expand Down Expand Up @@ -426,7 +407,7 @@ private void handleAlert(final RecordAlert recordAlert) {

private void handleAlert(Alert alert) {
String uri = alert.getUri();
LOGGER.debug("Alert: {} URL: {}", this.lastAlert, uri);
LOGGER.debug("Alert: {} URL: {}", alert.getAlertId(), uri);
// Loop through global rules and apply as necessary
for (AlertFilter filter : this.globalAlertFilterParam.getGlobalAlertFilters()) {
if (filter.appliesToAlert(alert, true)) {
Expand Down Expand Up @@ -499,9 +480,7 @@ private Alert getAlert(RecordAlert recordAlert) {
}

@Override
public void sessionChanged(Session session) {
this.lastAlert = -1;
}
public void sessionChanged(Session session) {}

@Override
public void sessionAboutToChange(Session session) {
Expand Down

0 comments on commit b24a40e

Please sign in to comment.