Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
89 changes: 87 additions & 2 deletions src/client/shell/dock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -876,8 +876,51 @@ impl RightDockState {
if entry.is_dir {
self.files_tab.toggle_selected_expanded();
} else if let Some(root) = &self.files_tab.cached_root {
let rel_str = entry.relative_path.to_string_lossy();

// 1. Verificación anti-fugas de archivos sensibles (credenciales, .env, claves)
if super::telemetry::is_sensitive_file(&rel_str) {
let lines = vec![
"[SEGURIDAD: PREVISUALIZACIÓN BLOQUEADA]".to_string(),
"".to_string(),
format!("Archivo: {}", entry.name),
"Ruta clasificada como credencial o archivo con secretos sensibles."
.to_string(),
"La previsualización en texto plano ha sido bloqueada automáticamente"
.to_string(),
"para prevenir fugas accidentales en pantalla compartida o logs."
.to_string(),
];
self.quick_peek =
Some(QuickPeekState::new(format!("🔒 {}", entry.name), lines));
return;
}

// 2. Verificación de path traversal
if entry
.relative_path
.components()
.any(|c| matches!(c, std::path::Component::ParentDir))
{
let lines =
vec!["[Error: Ruta fuera de los límites del workspace]".to_string()];
self.quick_peek = Some(QuickPeekState::new(entry.name, lines));
return;
}

let file_path = root.join(&entry.relative_path);
// Lectura acotada con tope de tamaño (máx 128 KB y 100 líneas) para evitar freeze
let outside_workspace = matches!(
(root.canonicalize(), file_path.canonicalize()),
(Ok(canon_root), Ok(canon_file)) if !canon_file.starts_with(&canon_root)
);
if outside_workspace {
let lines =
vec!["[Error: Acceso bloqueado - ruta fuera del workspace]".to_string()];
self.quick_peek = Some(QuickPeekState::new(entry.name, lines));
return;
}

// 3. Lectura acotada con tope de tamaño y sanitización línea a línea
let lines = match std::fs::File::open(&file_path) {
Ok(file) => {
use std::io::{BufRead, BufReader, Read};
Expand All @@ -890,7 +933,7 @@ impl RightDockState {
Ok(0) => break, // EOF o reached 128KB
Ok(_) => {
let trimmed = line_buf.trim_end_matches(['\r', '\n']);
collected.push(trimmed.to_string());
collected.push(super::telemetry::sanitize_secret_line(trimmed));
}
Err(_) => {
if collected.is_empty() {
Expand Down Expand Up @@ -2513,6 +2556,48 @@ mod tests {
assert!(!dock.files_tab.entries[0].is_expanded);
}

#[test]
fn activate_file_selection_blocks_sensitive_files_and_sanitizes_tokens() {
let root = TreeFixture::new();
std::fs::write(root.0.join(".env"), "DATABASE_URL=postgres://user:super_secret_pw@db:5432\nAPI_KEY=sk-proj-1234567890abcdef1234567890\n").unwrap();
std::fs::write(
root.0.join("safe.txt"),
"Authorization: Bearer secret_access_token_12345\nNormal text line\n",
)
.unwrap();

let mut dock = RightDockState::default();
dock.files_tab.refresh_if_needed(&root.0);

let env_idx = dock
.files_tab
.entries
.iter()
.position(|e| e.name == ".env")
.unwrap();
dock.files_tab.selected_index = env_idx;
dock.activate_file_selection();

let peek = dock.quick_peek.as_ref().unwrap();
assert!(peek.title.contains("🔒"));
assert!(peek.lines[0].contains("SEGURIDAD: PREVISUALIZACIÓN BLOQUEADA"));
assert!(!peek.lines.iter().any(|l| l.contains("super_secret_pw")));

let safe_idx = dock
.files_tab
.entries
.iter()
.position(|e| e.name == "safe.txt")
.unwrap();
dock.files_tab.selected_index = safe_idx;
dock.activate_file_selection();

let safe_peek = dock.quick_peek.as_ref().unwrap();
assert_eq!(safe_peek.title, "safe.txt");
assert_eq!(safe_peek.lines[0], "Authorization: Bearer ********");
assert_eq!(safe_peek.lines[1], "Normal text line");
}

#[test]
fn tree_navigation_scrolls_and_root_change_resets_tree() {
let root = TreeFixture::new();
Expand Down
37 changes: 36 additions & 1 deletion src/client/shell/dock_icons.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,13 @@ fn match_exact_filename(name: &str) -> Option<FileIcon> {
glyph: "⚙",
color: Color::Rgb(109, 128, 134), // Gris frío (#6d8086)
}),
".env" | ".env.example" | ".env.local" | ".env.development" | ".env.production" => {
".env" | ".env.local" | ".env.development" | ".env.production" => {
Some(FileIcon {
glyph: "🔒",
color: Color::Rgb(243, 139, 168), // Rojo de alerta/seguridad (#f38ba8)
})
}
".env.example" | ".env.sample" | ".env.template" => {
Some(FileIcon {
glyph: "⚙",
color: Color::Rgb(249, 226, 175), // Oro/Amarillo tenue (#f9e2af)
Expand Down Expand Up @@ -308,6 +314,13 @@ pub fn resolve_file_icon(name: &str) -> FileIcon {
return icon;
}

if super::telemetry::is_sensitive_file(name) {
return FileIcon {
glyph: "🔒",
color: Color::Rgb(243, 139, 168), // Rojo de alerta/seguridad (#f38ba8)
};
}

if let Some(dot_pos) = name.rfind('.') {
if dot_pos + 1 < name.len() {
let ext = &name[dot_pos + 1..];
Expand Down Expand Up @@ -381,4 +394,26 @@ mod tests {
let no_ext = resolve_file_icon("sin_extension");
assert_eq!(no_ext.glyph, "≡");
}

#[test]
fn sensitive_files_resolve_lock_icon() {
let env_file = resolve_file_icon(".env");
assert_eq!(env_file.glyph, "🔒");
assert_eq!(env_file.color, Color::Rgb(243, 139, 168));

let env_prod = resolve_file_icon(".env.production");
assert_eq!(env_prod.glyph, "🔒");
assert_eq!(env_prod.color, Color::Rgb(243, 139, 168));

let env_example = resolve_file_icon(".env.example");
assert_eq!(env_example.glyph, "⚙");

let creds = resolve_file_icon("credentials.json");
assert_eq!(creds.glyph, "🔒");
assert_eq!(creds.color, Color::Rgb(243, 139, 168));

let privkey = resolve_file_icon("server.key");
assert_eq!(privkey.glyph, "🔒");
assert_eq!(privkey.color, Color::Rgb(243, 139, 168));
}
}
Loading
Loading