atomic-server
atomic-server copied to clipboard
Don't subscribe to external resources
Currently, if a client uses the SUBSCRIBE webhook message, the server will perform an authorization check for a resouce that it probably has not stored. This could lead to unnecessary work on the server.
E.g.
2022-07-21T11:36:21.421586Z INFO actix_server::server: Actix runtime found; starting in Actix runtime
fetching body of http://localhost:3000
thread 'main' panicked at 'fetching localhost:3000', lib/src/client.rs:53:9
stack backtrace:
0: rust_begin_unwind
at /rustc/a8314ef7d0ec7b75c336af2c9857bfaf43002bfc/library/std/src/panicking.rs:584:5
1: core::panicking::panic_fmt
at /rustc/a8314ef7d0ec7b75c336af2c9857bfaf43002bfc/library/core/src/panicking.rs:142:14
2: atomic_lib::client::fetch_body
at ./lib/src/client.rs:53:9
3: atomic_lib::client::fetch_resource
at ./lib/src/client.rs:22:16
4: atomic_lib::storelike::Storelike::fetch_resource
at ./lib/src/storelike.rs:132:13
5: atomic_lib::storelike::Storelike::handle_not_found
at ./lib/src/storelike.rs:207:9
6: <atomic_lib::db::Db as atomic_lib::storelike::Storelike>::get_resource
at ./lib/src/db.rs:290:23
7: <atomic_server::commit_monitor::CommitMonitor as actix::handler::Handler<atomic_server::actor_messages::Subscribe>>::handle
at ./server/src/commit_monitor.rs:47:15
8: <actix::address::envelope::SyncEnvelopeProxy<M> as actix::address::envelope::EnvelopeProxy<A>>::handle
at /Users/joep/.cargo/registry/src/github.com-1ecc6299db9ec823/actix-0.12.0/src/address/envelope.rs:80:23
9: <actix::address::envelope::Envelope<A> as actix::address::envelope::EnvelopeProxy<A>>::handle
at /Users/joep/.cargo/registry/src/github.com-1ecc6299db9ec823/actix-0.12.0/src/address/envelope.rs:53:9
The solution is probably to only handle subscribes for resources on the server itself, so simply check the first part of the URL.