Skip to content

Commit

Permalink
Merge pull request #6060 from kingthorin/cp-file
Browse files Browse the repository at this point in the history
custompayloads: Ensure file is readable for multi payload import
  • Loading branch information
psiinon authored Jan 8, 2025
2 parents 57b13a0 + e771929 commit 7cf8605
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 4 deletions.
2 changes: 2 additions & 0 deletions addOns/custompayloads/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
- Update minimum ZAP version to 2.16.0.
- Maintenance changes.
- The superfluous/unused ID element of the custom payloads has been removed from the GUI and config.
- Now depends on the Common Library add-on.

### Added
- Add help button to Options panel and add further detailed Help content.

### Fixed
- The add-on will no longer attempt to save or load Payloads for which there is no Category.
- Ensure file is selected, exists, and is readable when attempting to import multiple payloads.

## [0.13.0] - 2023-11-10
### Changed
Expand Down
10 changes: 10 additions & 0 deletions addOns/custompayloads/custompayloads.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,14 @@ zapAddOn {
manifest {
author.set("ZAP Dev Team")
url.set("https://www.zaproxy.org/docs/desktop/addons/custom-payloads/")

dependencies {
addOns {
register("commonlib") {
version.set(">= 1.17.0 & < 2.0.0")
}
}
}
}

apiClientGen {
Expand All @@ -18,5 +26,7 @@ zapAddOn {
}

dependencies {
zapAddOn("commonlib")

testImplementation(project(":testutils"))
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import javax.swing.JButton;
import javax.swing.JFileChooser;
import org.parosproxy.paros.Constant;
import org.zaproxy.addon.commonlib.ui.ReadableFileChooser;
import org.zaproxy.zap.utils.DisplayUtils;

public class CustomMultiplePayloadDialog extends AbstractColumnDialog<CustomPayload> {
Expand All @@ -50,13 +51,19 @@ public CustomMultiplePayloadDialog(Window owner, CustomPayload payload) {
this.addFileButtonListener(fileButton);
}

@Override
public String validateFields() {
return multiplePayload == null
? Constant.messages.getString(
"custompayloads.options.dialog.addMultiplePayload.file.error.text")
: null;
}

public void addFileButtonListener(JButton fileButton) {
fileButton.addActionListener(
e -> {
JFileChooser chooser = new JFileChooser();
int result = chooser.showOpenDialog(this);

if (result == JFileChooser.APPROVE_OPTION) {
JFileChooser chooser = new ReadableFileChooser();
if (chooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) {
multiplePayload = chooser.getSelectedFile();
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ custompayloads.options.dialog.addMultiplePayload.addPayload.button.name = Add Mu
custompayloads.options.dialog.addMultiplePayload.duplicates.checkbox.label = Prevent Duplicates
custompayloads.options.dialog.addMultiplePayload.error.text = An error occurred while importing the payloads:\n{0}
custompayloads.options.dialog.addMultiplePayload.error.title = Error Adding Payloads
custompayloads.options.dialog.addMultiplePayload.file.error.text = Please select a file to import.
custompayloads.options.dialog.addMultiplePayload.selectFile.button.name = Select File
custompayloads.options.dialog.addMultiplePayload.title = Add Multiple Payloads
custompayloads.options.dialog.category = Category
Expand Down

0 comments on commit 7cf8605

Please sign in to comment.