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

fix: Check for sender in internal calls #80

Merged
merged 1 commit into from
Dec 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion contracts/hub/router/src/execute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,7 @@ pub fn execute_release_escrow(

ensure!(
transfer_amount.checked_add(remaining_withdraw_amount)? == amount,
ContractError::new("Amount mismatch after trasnfer calculations")
ContractError::new("Amount mismatch after transfer calculations")
);

if !transfer_amount.is_zero() {
Expand Down
4 changes: 4 additions & 0 deletions contracts/hub/router/src/ibc/receive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@ pub fn ibc_receive_internal_call(
info: MessageInfo,
msg: IbcPacketReceiveMsg,
) -> Result<Response, ContractError> {
ensure!(
info.sender == env.contract.address,
ContractError::Unauthorized {}
);
// Get the chain data from current channel received
let channel = msg.packet.dest.channel_id;
let chain_uid = CHANNEL_TO_CHAIN_UID.load(deps.storage, channel)?;
Expand Down
2 changes: 1 addition & 1 deletion contracts/liquidity/factory/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ pub fn execute(
ibc::ack_and_timeout::ibc_ack_packet_internal_call(deps, info, env, ack)
}
ExecuteMsg::IbcCallbackReceive { receive_msg } => {
ibc::receive::ibc_receive_internal_call(deps, env, receive_msg)
ibc::receive::ibc_receive_internal_call(deps, env, info, receive_msg)
}
ExecuteMsg::NativeReceiveCallback { msg } => {
execute_native_receive_callback(deps, env, info, msg)
Expand Down
8 changes: 7 additions & 1 deletion contracts/liquidity/factory/src/ibc/receive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
use cosmwasm_std::entry_point;
use cosmwasm_std::{
ensure, from_json, to_json_binary, CosmosMsg, DepsMut, Env, IbcPacketReceiveMsg,
IbcReceiveResponse, Response, StdError, SubMsg, Uint128, WasmMsg,
IbcReceiveResponse, MessageInfo, Response, StdError, SubMsg, Uint128, WasmMsg,
};
use euclid::{
chain::{ChainUid, CrossChainUserWithLimit},
Expand Down Expand Up @@ -54,8 +54,14 @@ pub fn ibc_packet_receive(
pub fn ibc_receive_internal_call(
deps: DepsMut,
env: Env,
info: MessageInfo,
msg: IbcPacketReceiveMsg,
) -> Result<Response, ContractError> {
ensure!(
info.sender == env.contract.address,
ContractError::Unauthorized {}
);

let router = msg.packet.src.port_id.replace("wasm.", "");
let state = STATE.load(deps.storage)?;
ensure!(
Expand Down
Loading