Skip to content

Commit a4c72b6

Browse files
committed
fix: enable HTML autoescape in minijinja templates to prevent XSS
1 parent 8dd9403 commit a4c72b6

1 file changed

Lines changed: 3 additions & 1 deletion

File tree

src/commands.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use std::io::Read;
1212
use std::path::PathBuf;
1313
use tokio::sync::oneshot;
1414

15-
use minijinja::{path_loader, Environment};
15+
use minijinja::{path_loader, AutoEscape, Environment};
1616
use std::sync::{Arc, OnceLock, RwLock};
1717

1818
use syntect::html::{ClassStyle, ClassedHTMLGenerator};
@@ -57,6 +57,7 @@ where
5757
}
5858

5959
let mut env = Environment::new();
60+
env.set_auto_escape_callback(|_| AutoEscape::Html);
6061
env.set_loader(loader);
6162
env.add_template_owned("template".to_string(), source.to_string())?;
6263
cache.insert(hash, Arc::new(env));
@@ -685,6 +686,7 @@ impl Command for MjCommand {
685686

686687
// Set up environment and get template
687688
let mut env = Environment::new();
689+
env.set_auto_escape_callback(|_| AutoEscape::Html);
688690
let tmpl = if let Some(ref path) = file {
689691
// File mode: resolve from filesystem only
690692
let path = std::path::Path::new(path);

0 commit comments

Comments
 (0)