Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AssetServer out of bounds protection #18088

Open
wants to merge 16 commits into
base: main
Choose a base branch
from

Conversation

Threadzless
Copy link
Contributor

Addresses Issue #18073

@alice-i-cecile alice-i-cecile added C-Bug An unexpected or incorrect behavior A-Assets Load files from disk to use for things like images, models, and sounds X-Contentious There are nontrivial implications that should be thought through S-Needs-Review Needs reviewer attention (from anyone!) to move forward labels Feb 28, 2025
Copy link
Contributor

@viridia viridia left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the overall approach, but I think that the tests could be more comprehensive.

@Threadzless
Copy link
Contributor Author

Threadzless commented Feb 28, 2025

I added more tests. Now a CI/build fails on github, but succeeds on my machine. Idk what to do from here

Comment on lines +437 to +447
pub fn load_acquire_with_settings_override<
'a,
A: Asset,
S: Settings,
G: Send + Sync + 'static,
>(
&self,
path: impl Into<AssetPath<'a>>,
settings: impl Fn(&mut S) + Send + Sync + 'static,
guard: G,
) -> Handle<A> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't like the duplication of all of these functions. In almost all cases you'd set the mode globally and never need the other variant I think? And if we really want a way to opt out of the sandbox can't we just make load_with_meta_transform public instead of creating every combination of how it can be called as separate methods?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you have a scripting system, you would give that system access to AssetServer::load, and then use AssetServer::load_override. If UnapprovedPathMode (previously OutOfBoundsMode) is Deny, this would let the developers load whatever files, while preventing mods from doing the same.

We could get rid of all _override functions and expose load_with_meta_transform, but that would make using this security feature more confusing

@Threadzless
Copy link
Contributor Author

Now denied asset loads return Handle::default() and print an error. Documentation has been updated.

@@ -1902,7 +1902,7 @@ mod tests {
dir.insert_asset_text(Path::new(a_path), a_ron);

let mut app = App::new();
let (gated_memory_reader, gate_opener) = GatedReader::new(MemoryAssetReader { root: dir });
let (gated_memory_reader, _gate_opener) = GatedReader::new(MemoryAssetReader { root: dir });
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is still not quite right. Just remove the GatedReader::new entirely, and I think it should work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Assets Load files from disk to use for things like images, models, and sounds C-Bug An unexpected or incorrect behavior S-Needs-Review Needs reviewer attention (from anyone!) to move forward X-Contentious There are nontrivial implications that should be thought through
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants