-
Notifications
You must be signed in to change notification settings - Fork 6
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
Authorization using or
and tx-sender
#70
Comments
or
and tx-sender
or
and tx-sender
Great findings! — We also just ran
/cc @faculerena, @CoinFabrik |
Wrong!!! Authorizing operations that don't involve any assets (STX/NFT/FT) movement (transfer, burn) using Transactions with assets operations should be and are secured with post-conditions. |
Hey, I just saw this. Maybe this article written by an auditor from CoinFabrik could be useful in clarifying where we are coming from when we say |
https://app.sigle.io/friedger.id.stx/HuOT9tNQC8fTXOsK28D7e And from my personal notes that I wrote in 2022: Securing function callsSome contract functions should be callable only by a specific addresses. Contract owner guard exampleBasic primitives: ;; we have to store who is contract owner and to do so we assign tx-sender to constant
(define-constant CONTRACT_OWNER tx-sender)
;; reusable error
(define-constant ERR_UNAUTHORIZED (err u401))
(define-private (isSenderTheOwner)
(is-eq tx-sender CONTRACT_OWNER)
)
(define-private (isCallerTheOwner)
(is-eq contract-caller CONTRACT_OWNER)
)
(define-private (isOwner)
(or (is-eq tx-sender CONTRACT_OWNER) (is-eq contract-caller CONTRACT_OWNER)
) All functions with tokens side-effects (transferring, burning STX/FT/NFT) can and should be guarded with Example: (define-constant CONTRACT_ADDRESS (as-contract tx-sender))
(define-data-var accumulatedFees uint)
(define-public (withdraw-contract-fees (recipient principal))
(begin
(asserts! (isSenderTheOwner) ERR_UNAUTHORIZED)
(as-contract (stx-transfer? (var-get accumulatedFees) CONTRACT_ADDRESS recipient))
)
) All functions without tokens side-effect, that can change important values in contract should be guarded with Extra solutionSecuring functions with 1 micro STX is worth next to nothing, but it will enforce post-conditions as security measure. |
Hi @LNow , I'm Franco from Coinfabrik's audit team. I agree that using the tx-sender authentication method results in a high-severity issue when the transaction doesn't involve token transfers. In those cases, post-conditions can't prevent an attack, and the impact could be really high. Also, I want to add that this is an issue even when tokens are involved, although the severity is lower. We can't discard it based on an assumption on how users interact with the dapp, and AFAIK, the deny mode isn't the default for Stacks. As you mentioned, tx-sender provides more flexibility and simplifies contract composition. So, the development team might decide not to replace it with contract-caller. If that's the case, the issue remains, and the risk should be acknowledged and properly documented. Regarding the extra solution, I remember reading about it when I first looked into the ecosystem. Now that I'm thinking about it again, I think it only partially addresses the issue. Adding a token transfer will prevent users from falling for most phishing attacks, but not the ones where the user expects a token transfer. Since users can't specify the recipient in the post-conditions (or addresses they don't want to transfer to), phishing attacks using fake DeFi apps with actions like staking, swapping, or lending could still work. Let me know your insight and thank you for sharing your notes and opinion on this. |
@fbregante when user decides to signs tx composed with
Not only you can, but I'd say that you should. Otherwise you would have to mark functions such as When you use
I used transferring STX only as an example, because it is the easiest to understand and the cheapest (execution-costs wise) token operation Lastly, I think that in the long run reporting |
We view this as a minor issue. While it can be exploited, the likelihood is low, and the impact is limited to the user who chooses to use allow-mode.
This is a strong argument against contract-caller, as Stacks doesn't provide a built-in way to batch transactions.
It's an interesting concept. The wallet could have a unique token dedicated solely to authentication within that protocol.
Audit recommendations are just a starting point. The people building the project know it best and can make the most suitable choice. It's helpful to get feedback and refine our recommendations through talks like this. Thanks again for that! |
This was updated to have contract-caller on the functions. After careful talk with the team this was the decision made |
For the sake of clarity (pun intended) |
Using
or
in the authorization processI found out that this way of authorizing the ownership of a name happens in several places inside the
BNS-V2
contract:Authorizing using
tx-sender
is a known security issue in Clarity. A malicious contract can deliberately avoid using theas-contract
function when calling other contracts, causing thetx-sender
value to remain the same as the original sender. At first glance, this approach seems to validate if only one of the conditions is true (because theor
operator is used).Using
tx-sender
for authorizationThere are places where
tx-sender
is used for the authorization inside theBNS-V2
contract:I found these at first glance and I'm not completely sure of their impact, but they seem worth checking out. Thank you!
CC: @moodmosaic @wileyj
The text was updated successfully, but these errors were encountered: