feat(conversation): add validation for destination hash in ping functionality to ensure correct format and existence
This commit is contained in:
@@ -168,9 +168,20 @@ export default {
|
||||
}
|
||||
},
|
||||
async onPingDestination() {
|
||||
if (!this.peer || !this.peer.destination_hash) {
|
||||
DialogUtils.alert("Invalid destination hash");
|
||||
return;
|
||||
}
|
||||
|
||||
const destinationHash = this.peer.destination_hash;
|
||||
if (destinationHash.length !== 32 || !/^[0-9a-fA-F]+$/.test(destinationHash)) {
|
||||
DialogUtils.alert("Invalid destination hash format");
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
// ping destination
|
||||
const response = await window.axios.get(`/api/v1/ping/${this.peer.destination_hash}/lxmf.delivery`, {
|
||||
const response = await window.axios.get(`/api/v1/ping/${destinationHash}/lxmf.delivery`, {
|
||||
params: {
|
||||
timeout: 30,
|
||||
},
|
||||
@@ -181,7 +192,7 @@ export default {
|
||||
const rttDurationString = `${rttMilliseconds} ms`;
|
||||
|
||||
const info = [
|
||||
`Valid reply from ${this.peer.destination_hash}`,
|
||||
`Valid reply from ${destinationHash}`,
|
||||
`Duration: ${rttDurationString}`,
|
||||
`Hops There: ${pingResult.hops_there}`,
|
||||
`Hops Back: ${pingResult.hops_back}`,
|
||||
|
||||
Reference in New Issue
Block a user