Context
PR #260 introduces a breaking change involving ConnectorConfig: the config now holds a new attr record_index. The purpose of this design is for record_index could be carried from collect_outbound_routes to WsBusSink.publish() then ClientManager.broadcast() could gate message base on clients' permission bitmap.
However, this design proves unoptimal due to several reasons:
- The extra
record_index key in OutboundRoute.config could create a bug where the outbound route is constructed with record_index whose value divert from the record registration order. When record_index reaches OutboundRoute.config as encoded String, there are two record_key in that config and when ConnectorConfig::from_query(&config) a record_key branch needed to construct back record_key into ConnectorConfig. This make record_key a reserved keyword in from_query and we want to avoid that. The current flow has no error simply because the correct record_key lands as last item in config, and that's not strict enough;
- The index reaches broadcasting by taking a detour from
usize -> String (carried in OutboundRoute.config) -> usize when reaching broadcasting. This could be avoided;
Proposal
- Add
pub record_index to OutboundRoute. ConnectorConfig keep record_index;
- Change the assignment of
record_index: in pump_sink, after ConnectorConfig::from_query(&config), set ConnectorConfig.record_index to Some(record_index). This way, users could not override assigned record indexes by passing in a record_index param when sending request. This is the only way to fix the security leak and it is better than changing the Connector::publish signature as 1) that change will propagate to at least six call sites; 2) not all call sites have an use for such index;
- Remove
record_index branch from ConnectorConfig::from_query so the reserved keyword issue solved;
- Add #[non_exhaustive] to ConnectorConfig, since it's already a breaking change;
Connector::publish stays the same;
- Rewrite
collect_outbound_routes_preserves_record_order to check list_records()[route.record_index].record_key == key instead of parsing the config pair;
Tests
record_index that is wrongly passed when building a outbound route will be overridden by the correct id, clients having valid grant could still receive message;
Context
PR #260 introduces a breaking change involving
ConnectorConfig: the config now holds a new attrrecord_index. The purpose of this design is forrecord_indexcould be carried fromcollect_outbound_routestoWsBusSink.publish()thenClientManager.broadcast()could gate message base on clients' permission bitmap.However, this design proves unoptimal due to several reasons:
record_indexkey inOutboundRoute.configcould create a bug where the outbound route is constructed withrecord_indexwhose value divert from the record registration order. Whenrecord_indexreachesOutboundRoute.configas encodedString, there are tworecord_keyin thatconfigand whenConnectorConfig::from_query(&config)arecord_keybranch needed to construct backrecord_keyintoConnectorConfig. This makerecord_keya reserved keyword infrom_queryand we want to avoid that. The current flow has no error simply because the correctrecord_keylands as last item inconfig, and that's not strict enough;usize->String(carried inOutboundRoute.config) ->usizewhen reaching broadcasting. This could be avoided;Proposal
pub record_indexto OutboundRoute.ConnectorConfigkeeprecord_index;record_index: inpump_sink, afterConnectorConfig::from_query(&config), setConnectorConfig.record_indextoSome(record_index). This way, users could not override assigned record indexes by passing in arecord_indexparam when sending request. This is the only way to fix the security leak and it is better than changing theConnector::publishsignature as 1) that change will propagate to at least six call sites; 2) not all call sites have an use for such index;record_indexbranch fromConnectorConfig::from_queryso the reserved keyword issue solved;Connector::publishstays the same;collect_outbound_routes_preserves_record_orderto checklist_records()[route.record_index].record_key == keyinstead of parsing the config pair;Tests
record_indexthat is wrongly passed when building a outbound route will be overridden by the correct id, clients having valid grant could still receive message;