select the saved camera by its id before falling back to its name, so that a camera with the same name is not opened in its place
What changed, and why it matters
This commit fixes a webcam selection bug in Sparrow Wallet. Previously, if two cameras had the same name, the wallet might open the wrong camera. Now it first tries to match the saved camera by its unique ID, and only falls back to matching by name if no ID match is found. This is a correctness/usability fix rather than a clear-cut security vulnerability, though opening the wrong camera could have minor privacy implications.
Treat as a low-risk bugfix. No urgent security response required, but include in release notes as a webcam reliability improvement. If QR code scanning is used for sensitive operations, verify that camera selection now behaves correctly with multiple identical cameras attached.
Security signals we found
Device selection ambiguity resolved by prioritizing unique identifier
Potential wrong-camera-open scenario prevented
No input validation, injection, or cryptographic issues evident
No explicit security boundary crossed in the diff
Evidence from the diff
The patch changes WebcamService.java to prioritize unique device ID matching over name matching when selecting a previously saved webcam. The old code iterated through available devices and returned the first device matching either the saved unique ID or the saved name, with both checks inside the same loop. Because identical cameras share names, a name match could occur before an ID match elsewhere in the list, causing the wrong device to be selected. The new code uses two sequential stream filters: first exact unique ID match, then name fallback. This is a defensive fix against device mis-selection.
Changed components
src/main/java/com/sparrowwallet/sparrow/control/WebcamService.javaInspect captured patch +4 / −10
### src/main/java/com/sparrowwallet/sparrow/control/WebcamService.java
@@ -160,16 +160,10 @@ protected Image call() throws Exception {
}
}
} else if(Config.get().getWebcamDevice() != null) {
- for(CaptureDevice webcam : availableDevices) {
- if(webcam.getUniqueId().equals(Config.get().getWebcamDeviceId())) {
- selectedDevice = webcam;
- break;
- }
- if(webcam.getName().equals(Config.get().getWebcamDevice())) {
- selectedDevice = webcam;
- break;
- }
- }
+ //Identical cameras share a name, so the saved ID is looked for first, and the name only where no camera has that ID
+ selectedDevice = availableDevices.stream().filter(webcam -> webcam.getUniqueId().equals(Config.get().getWebcamDeviceId())).findFirst()
+ .or(() -> availableDevices.stream().filter(webcam -> webcam.getName().equals(Config.get().getWebcamDevice())).findFirst())
+ .orElse(selectedDevice);
}
device = selectedDevice;Why this scored 23/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.