Skip to content

Commit

Permalink
cache: do not trust the filesystem
Browse files Browse the repository at this point in the history
  • Loading branch information
uael committed Dec 18, 2024
1 parent 3339e69 commit 95737d8
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion backend/windmill-common/src/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,10 @@ const _: () = {
_ => Ok(None),
}
}

fn validate(&self) -> bool {
!self.code.is_empty()
}
}

impl fs::Bundle for ScriptMetadata {
Expand Down Expand Up @@ -684,6 +688,10 @@ mod fs {
fn import(&mut self, item: Self::Item, data: Vec<u8>) -> error::Result<()>;
/// Export the `item` into a `Vec<u8>`.
fn export(&self, item: Self::Item) -> error::Result<Option<Vec<u8>>>;
/// Validate the bundle.
fn validate(&self) -> bool {
true
}
}

/// An item that can be imported/exported from/into the file-system.
Expand Down Expand Up @@ -716,7 +724,10 @@ mod fs {
Ok(data)
};
match import() {
Ok(data) => return Ok(data),
Ok(data) if data.validate() => return Ok(data),
Ok(_) => tracing::warn!(
"Failed to import from file-system, invalid data, fetch source..: {path:?}"
),
Err(err) => tracing::warn!(
"Failed to import from file-system, fetch source..: {path:?}: {err:?}"
),
Expand Down Expand Up @@ -807,6 +818,10 @@ mod fs {
_ => Ok(None),
}
}

fn validate(&self) -> bool {
self.as_ref().map_or(true, T::validate)
}
}

// Bundle pair.
Expand All @@ -830,6 +845,10 @@ mod fs {
_ => self.1.export(item),
}
}

fn validate(&self) -> bool {
self.0.validate() && self.1.validate()
}
}

// Implement `Item`.
Expand Down

0 comments on commit 95737d8

Please sign in to comment.