BuyerAgent contract's authorization system can be completely bypassed by deploying it with a malicious Swan contract implementation. This allows unauthorized access to all privileged functions including treasury management, purchasing decisions, and state updates.
The vulnerability exists in the constructor's unchecked initialization of the Swan contract: https://github.com/Cyfrin/2024-10-swan-dria/blob/c8686b199daadcef3161980022e12b66a5304f8e/contracts/swan/BuyerAgent.sol#L120-L144
The authorization check in onlyAuthorized modifier can be bypassed: https://github.com/Cyfrin/2024-10-swan-dria/blob/c8686b199daadcef3161980022e12b66a5304f8e/contracts/swan/BuyerAgent.sol#L105-L111
The onlyAuthorized modifier: https://github.com/Cyfrin/2024-10-swan-dria/blob/c8686b199daadcef3161980022e12b66a5304f8e/contracts/swan/BuyerAgent.sol#L105-L111
The Bug: The access control check relies on two conditions:
swan.isOperator(msg.sender)
msg.sender != owner()
However, there's a flaw in the initialization sequence where the Swan contract address is set in the constructor but there's no validation that it's a legitimate Swan contract implementation.
Missing Contract Validation:
The constructor blindly trusts the provided _operator address is a legitimate Swan contract
An attacker could deploy a malicious contract implementing the Swan interface
This would allow bypassing access controls through a compromised isOperator() check
Security Implications:
Full control over buyer agent operations
Ability to manipulate purchases and state updates
Access to treasury funds through withdrawal functions
Potential to lock or drain user funds
Attack vector:
It's all because the constructor blindly trusts the provided _operator address and casts it to Swan without verification:
This allows an attacker to deploy a malicious contract that always returns true for isOperator() checks, completely bypassing the authorization system.
Unauthorized access to privileged functions
Potential manipulation of buyer agent state
Ability to execute unauthorized purchases
Control over treasury withdrawals
The contest is live. Earn rewards by submitting a finding.
This is your time to appeal against judgements on your submissions.
Appeals are being carefully reviewed by our judges.