PortSwigger / burp-extensions-montoya-api

Burp Extensions Api
Other
139 stars 5 forks source link

Persistence API request #48

Closed Static-Flow closed 1 year ago

Static-Flow commented 1 year ago

Playing around with the persistence APIs and noticed there isn't a "keyExists" type of method. This requires me to do things like this:

try {
    String val = api.persistence().extensionData().getString(KEY);
} catch (NullPointerException e) {
    //Do nothing
}

because if the extension checks for a key on load but its the first time the extension is loaded the key will never exist and a NullPointer is thrown.

There is a ListKeys() method which gets all keys but I'd rather not have to call that and loop through it looking for mine.

Also while we're on the topic, what was the rationale for having multiple Persisted types? Why not just leave it a generic list of type Object and let the user cast it to what they expect it to be. Presumably the Extension developer already knows the type they are storing so typing the type to the API seems overly restrictive.

Hannah-PortSwigger commented 1 year ago

Hi

The get method for PersistedObjects returns null if there is no mapping for the specified key. If you include a null check, you can determine whether a key is present or not.

The reasoning behind the different Persisted types is that we cannot persist any random object to the disk. If we had a random object, we wouldn't know what properties need to be saved to the disk or if they can be saved in that manner.

If you would like to save a custom object with persistence, we would recommend serializing the object into a ByteArray, and then deserializing on load.