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

No Input Validation On _execute or safeTranferFrom #261

Closed
code423n4 opened this issue Jan 16, 2023 · 8 comments
Closed

No Input Validation On _execute or safeTranferFrom #261

code423n4 opened this issue Jan 16, 2023 · 8 comments
Labels
3 (High Risk) Assets can be stolen/lost/compromised directly bug Something isn't working duplicate-521 satisfactory satisfies C4 submission criteria; eligible for awards

Comments

@code423n4
Copy link
Contributor

Lines of code

https://github.com/code-423n4/2023-01-astaria/blob/main/src/ClearingHouse.sol#L114
https://github.com/code-423n4/2023-01-astaria/blob/main/src/ClearingHouse.sol#L169

Vulnerability details

Impact

An attacker can pass malicious tokenContract and encodedMetaData values.

Proof of Concept

The _execute function is called by safeTransferFrom and does not perform any input validation on the tokenContract and encodedMetaData arguments - neither at the _execute or safeTransferFrom levels.

function _execute(
address tokenContract, // collateral token sending the fake nft
address to, // buyer
uint256 encodedMetaData, //retrieve token address from the encoded data
uint256 // space to encode whatever is needed,
) internal {
IAstariaRouter ASTARIA_ROUTER = IAstariaRouter(_getArgAddress(0)); // get the router from the immutable arg

ClearingHouseStorage storage s = _getStorage();
address paymentToken = bytes32(encodedMetaData).fromLast20Bytes();

uint256 currentOfferPrice = _locateCurrentAmount({
    startAmount: s.auctionStack.startAmount,
    endAmount: s.auctionStack.endAmount,
    startTime: s.auctionStack.startTime,
    endTime: s.auctionStack.endTime,
    roundUp: true //we are a consideration we round up
});
uint256 payment = ERC20(paymentToken).balanceOf(address(this));

require(payment >= currentOfferPrice, "not enough funds received");

uint256 collateralId = _getArgUint256(21);
// pay liquidator fees here

ILienToken.AuctionStack[] storage stack = s.auctionStack.stack;

uint256 liquidatorPayment = ASTARIA_ROUTER.getLiquidatorFee(payment);

ERC20(paymentToken).safeTransfer(
    s.auctionStack.liquidator,
    liquidatorPayment
);

ERC20(paymentToken).safeApprove(
    address(ASTARIA_ROUTER.TRANSFER_PROXY()),
    payment - liquidatorPayment
);

ASTARIA_ROUTER.LIEN_TOKEN().payDebtViaClearingHouse(
    paymentToken,
    collateralId,
    payment - liquidatorPayment,
    s.auctionStack.stack
);

if (ERC20(paymentToken).balanceOf(address(this)) > 0) {
    ERC20(paymentToken).safeTransfer(
    ASTARIA_ROUTER.COLLATERAL_TOKEN().ownerOf(collateralId),
    ERC20(paymentToken).balanceOf(address(this))
    );
}
ASTARIA_ROUTER.COLLATERAL_TOKEN().settleAuction(collateralId);
}


function safeTransferFrom(
address from, // the from is the offerer
address to,
uint256 identifier,
uint256 amount,
bytes calldata data //empty from seaport
) public {
//data is empty and useless
_execute(from, to, identifier, amount);
}

Recommended Mitigation Steps

Perform input validation on either functions. A comment mentions that the data is useless; if that is the case, then either remove the function altogether or perform input validation regardless - as the function might be adopted further without the proper security mechanisms in place.

@code423n4 code423n4 added 3 (High Risk) Assets can be stolen/lost/compromised directly bug Something isn't working labels Jan 16, 2023
code423n4 added a commit that referenced this issue Jan 16, 2023
@Picodes
Copy link

Picodes commented Jan 24, 2023

You need to develop what could be the impact of this with regards to user funds

@c4-judge
Copy link
Contributor

Picodes marked the issue as duplicate of #564

@c4-judge
Copy link
Contributor

Picodes marked the issue as partial-25

@c4-judge c4-judge added the partial-25 Incomplete articulation of vulnerability; eligible for partial credit only (25%) label Jan 24, 2023
@c4-judge c4-judge added duplicate-521 satisfactory satisfies C4 submission criteria; eligible for awards and removed duplicate-564 partial-25 Incomplete articulation of vulnerability; eligible for partial credit only (25%) labels Feb 15, 2023
@c4-judge
Copy link
Contributor

Picodes marked the issue as satisfactory

@c4-judge c4-judge added downgraded by judge Judge downgraded the risk level of this issue QA (Quality Assurance) Assets are not at risk. State handling, function incorrect as to spec, issues with clarity, syntax and removed 3 (High Risk) Assets can be stolen/lost/compromised directly labels Feb 23, 2023
@c4-judge
Copy link
Contributor

Picodes changed the severity to QA (Quality Assurance)

@c4-judge c4-judge reopened this Feb 24, 2023
@c4-judge c4-judge added 3 (High Risk) Assets can be stolen/lost/compromised directly and removed downgraded by judge Judge downgraded the risk level of this issue QA (Quality Assurance) Assets are not at risk. State handling, function incorrect as to spec, issues with clarity, syntax labels Feb 24, 2023
@c4-judge
Copy link
Contributor

This previously downgraded issue has been upgraded by Picodes

@c4-judge
Copy link
Contributor

Picodes marked the issue as not a duplicate

@c4-judge
Copy link
Contributor

Picodes marked the issue as duplicate of #521

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3 (High Risk) Assets can be stolen/lost/compromised directly bug Something isn't working duplicate-521 satisfactory satisfies C4 submission criteria; eligible for awards
Projects
None yet
Development

No branches or pull requests

3 participants