The functions crossSwapTokensForExactTokens and crossSwapExactTokensForTokens of MarginRouter.sol do not check who is calling the function. They also do not check the contents of pairs and tokens nor do they check if the size of pairs and tokens is the same.
registerTradeAndBorrow within registerTrade does seem to do an entry check (require(isMarginTrader(msg.sender)) however as this is an external function msg.sender is the address of MarginRouter.sol, which will verify ok.
Calling these functions allow the caller to trade on behalf of marginswap, which could result in losing funds. Its possible to construct all parameters to circumvent the checks. Also the pairs can be fully specified; they are contract addresses that are called from getAmountsIn / getAmountsOut and from pair.swap. This way you can call arbitrary (self constructed) code, which can reentrantly call the marginswap code.
Recommend limiting who can call the functions. Perhaps whitelist contents of pairs and tokens. Check the size of pairs and tokens is the same.
werg (Marginswap) confirmed:
