Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 7afdad0

Browse files
committed
security: Fix 10 vulnerabilities, remove 12 dead code instances
Critical fixes: - Remove hardcoded admin/admin123 credentials from UserManager - Enable JWT signature verification (was disabled for debugging) - Redact secrets from /dev/config endpoint (was exposing os.environ) - Remove hardcoded SSH admin/admin credentials from hardware service - Add channel validation to prevent command injection in router interface Rust fixes: - Replace partial_cmp().unwrap() with .unwrap_or(Equal) to prevent NaN panics in 6 locations across core, signal, nn, mat crates - Replace .expect()/.unwrap() with safe fallbacks in utils, csi_receiver - Replace SystemTime unwrap with unwrap_or_default Dead code removed: - Duplicate imports (CORSMiddleware, os, Path, ABC, subprocess) - Unused AdaptiveRateLimit/RateLimitStorage/RedisRateLimitStorage (~110 lines) - Unused _log_authentication_event method - Unused Confidence::new_unchecked in Rust - Fix bare except: clause to except Exception: https://claude.ai/code/session_01Ki7pvEZtJDvqJkmyn6B714
1 parent ea452ba commit 7afdad0

23 files changed

Lines changed: 81 additions & 192 deletions

File tree

rust-port/wifi-densepose-rs/crates/wifi-densepose-core/src/types.rs

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -172,16 +172,6 @@ impl Confidence {
172172

173173
/// Creates a confidence value without validation (for internal use).
174174
///
175-
/// # Safety
176-
///
177-
/// The caller must ensure the value is in [0.0, 1.0].
178-
#[must_use]
179-
#[allow(dead_code)]
180-
pub(crate) fn new_unchecked(value: f32) -> Self {
181-
debug_assert!((0.0..=1.0).contains(&value));
182-
Self(value)
183-
}
184-
185175
/// Returns the raw confidence value.
186176
#[must_use]
187177
pub fn value(&self) -> f32 {
@@ -1009,7 +999,12 @@ impl PoseEstimate {
1009999
pub fn highest_confidence_person(&self) -> Option<&PersonPose> {
10101000
self.persons
10111001
.iter()
1012-
.max_by(|a, b| a.confidence.value().partial_cmp(&b.confidence.value()).unwrap())
1002+
.max_by(|a, b| {
1003+
a.confidence
1004+
.value()
1005+
.partial_cmp(&b.confidence.value())
1006+
.unwrap_or(std::cmp::Ordering::Equal)
1007+
})
10131008
}
10141009
}
10151010

rust-port/wifi-densepose-rs/crates/wifi-densepose-core/src/utils.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,11 @@ pub fn moving_average(data: &Array1<f64>, window_size: usize) -> Array1<f64> {
9898
let mut result = Array1::zeros(data.len());
9999
let half_window = window_size / 2;
100100

101-
// Safe unwrap: ndarray Array1 is always contiguous
102-
let slice = data.as_slice().expect("Array1 should be contiguous");
101+
// ndarray Array1 is always contiguous, but handle gracefully if not
102+
let slice = match data.as_slice() {
103+
Some(s) => s,
104+
None => return data.clone(),
105+
};
103106

104107
for i in 0..data.len() {
105108
let start = i.saturating_sub(half_window);

rust-port/wifi-densepose-rs/crates/wifi-densepose-mat/src/domain/disaster_event.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,8 @@ impl DisasterEvent {
310310
// Create new survivor
311311
let survivor = Survivor::new(zone_id, vitals, location);
312312
self.survivors.push(survivor);
313-
Ok(self.survivors.last().unwrap())
313+
// Safe: we just pushed, so last() is always Some
314+
Ok(self.survivors.last().expect("survivors is non-empty after push"))
314315
}
315316

316317
/// Find a survivor near a location

rust-port/wifi-densepose-rs/crates/wifi-densepose-mat/src/integration/csi_receiver.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -701,8 +701,14 @@ impl PcapCsiReader {
701701
};
702702

703703
if pcap_config.playback_speed > 0.0 {
704-
let packet_offset = packet.timestamp - self.start_time.unwrap();
705-
let real_offset = Utc::now() - self.playback_time.unwrap();
704+
let Some(start_time) = self.start_time else {
705+
return Ok(None);
706+
};
707+
let Some(playback_time) = self.playback_time else {
708+
return Ok(None);
709+
};
710+
let packet_offset = packet.timestamp - start_time;
711+
let real_offset = Utc::now() - playback_time;
706712
let scaled_offset = packet_offset
707713
.num_milliseconds()
708714
.checked_div((pcap_config.playback_speed * 1000.0) as i64)

rust-port/wifi-densepose-rs/crates/wifi-densepose-mat/src/integration/hardware_adapter.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -805,7 +805,7 @@ impl HardwareAdapter {
805805
let num_subcarriers = config.channel_config.num_subcarriers;
806806
let t = std::time::SystemTime::now()
807807
.duration_since(std::time::UNIX_EPOCH)
808-
.unwrap()
808+
.unwrap_or_default()
809809
.as_secs_f64();
810810

811811
// Generate simulated breathing pattern (~0.3 Hz)
@@ -1102,7 +1102,7 @@ fn rand_simple() -> f64 {
11021102
use std::time::SystemTime;
11031103
let nanos = SystemTime::now()
11041104
.duration_since(std::time::UNIX_EPOCH)
1105-
.unwrap()
1105+
.unwrap_or_default()
11061106
.subsec_nanos();
11071107
(nanos % 1000) as f64 / 1000.0 - 0.5
11081108
}

rust-port/wifi-densepose-rs/crates/wifi-densepose-mat/src/ml/debris_model.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ impl DebrisClassification {
164164
pub fn new(probabilities: Vec<f32>) -> Self {
165165
let (max_idx, &max_prob) = probabilities.iter()
166166
.enumerate()
167-
.max_by(|(_, a), (_, b)| a.partial_cmp(b).unwrap())
167+
.max_by(|(_, a), (_, b)| a.partial_cmp(b).unwrap_or(std::cmp::Ordering::Equal))
168168
.unwrap_or((7, &0.0));
169169

170170
// Check for composite materials (multiple high probabilities)
@@ -216,7 +216,7 @@ impl DebrisClassification {
216216
self.class_probabilities.iter()
217217
.enumerate()
218218
.filter(|(i, _)| *i != primary_idx)
219-
.max_by(|(_, a), (_, b)| a.partial_cmp(b).unwrap())
219+
.max_by(|(_, a), (_, b)| a.partial_cmp(b).unwrap_or(std::cmp::Ordering::Equal))
220220
.map(|(i, _)| MaterialType::from_index(i))
221221
}
222222
}

rust-port/wifi-densepose-rs/crates/wifi-densepose-mat/src/ml/vital_signs_classifier.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -593,7 +593,7 @@ impl VitalSignsClassifier {
593593
.enumerate()
594594
.skip(1) // Skip DC
595595
.take(30) // Up to ~30% of Nyquist
596-
.max_by(|(_, a), (_, b)| a.partial_cmp(b).unwrap())
596+
.max_by(|(_, a), (_, b)| a.partial_cmp(b).unwrap_or(std::cmp::Ordering::Equal))
597597
.unwrap_or((0, &0.0));
598598

599599
// Store dominant frequency in last position

rust-port/wifi-densepose-rs/crates/wifi-densepose-nn/src/tensor.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ impl Tensor {
285285
let result = a.map_axis(ndarray::Axis(axis), |row| {
286286
row.iter()
287287
.enumerate()
288-
.max_by(|(_, a), (_, b)| a.partial_cmp(b).unwrap())
288+
.max_by(|(_, a), (_, b)| a.partial_cmp(b).unwrap_or(std::cmp::Ordering::Equal))
289289
.map(|(i, _)| i as i64)
290290
.unwrap_or(0)
291291
});

rust-port/wifi-densepose-rs/crates/wifi-densepose-signal/src/features.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -490,7 +490,9 @@ impl PowerSpectralDensity {
490490
let peak_idx = positive_psd
491491
.iter()
492492
.enumerate()
493-
.max_by(|(_, a): &(usize, &f64), (_, b): &(usize, &f64)| a.partial_cmp(b).unwrap())
493+
.max_by(|(_, a): &(usize, &f64), (_, b): &(usize, &f64)| {
494+
a.partial_cmp(b).unwrap_or(std::cmp::Ordering::Equal)
495+
})
494496
.map(|(i, _)| i)
495497
.unwrap_or(0);
496498
let peak_frequency = positive_freq[peak_idx];

v1/src/api/main.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -380,10 +380,19 @@ async def api_metrics(request: Request):
380380
if settings.is_development and settings.enable_test_endpoints:
381381
@app.get(f"{settings.api_prefix}/dev/config")
382382
async def dev_config():
383-
"""Get current configuration (development only)."""
383+
"""Get current configuration (development only).
384+
385+
Returns a sanitized view -- secret keys and passwords are redacted.
386+
"""
387+
_sensitive = {"secret", "password", "token", "key", "credential", "auth"}
388+
raw = settings.dict()
389+
sanitized = {
390+
k: "***REDACTED***" if any(s in k.lower() for s in _sensitive) else v
391+
for k, v in raw.items()
392+
}
384393
domain_config = get_domain_config()
385394
return {
386-
"settings": settings.dict(),
395+
"settings": sanitized,
387396
"domain_config": domain_config.to_dict()
388397
}
389398

0 commit comments

Comments
 (0)