Skip to content
Access control Disclosed report Advanced

Attacker can use any non-enabled capability

The CosmWasm capability system only checks required capabilities at upload time, not at runtime, so a contract can omit the capability string and still execute any chain action. An attacker could deploy such a contract and perform actions the chain intended to block.

julianor Follow

Originally disclosed on HackerOne

Bounty$2,000 Low View original
  • Triaged in 1 hour
  • Fixed in 3 days
  • Paid in 3 days
  • Disclosed after 5 days

An attacker can deploy a cosmwasm contract on a chain and execute any action on that chain, even when the executing chain does not allow that capability. This issue stems from a naive implementation of capabilities and misleading documentation.

This goes against the Capabilites description in CAPABILITIES.md (https://github.com/CosmWasm/cosmwasm/blob/main/docs/CAPABILITIES.md):

The contract defines required capabilities. The environment defines its capabilities. If the required capabilities are all available, the contract can be used. 

We show that even if the required capabilities are not available, the capability can be used.

Steps to reproduce

  • Assume a chain that announced no capabilities to disallow contracts from executing certain paths.
  • The chain does allow users to execute those paths via regular non-wasm messages.
  1. The attacker comments out the generation of the capabilities-string in the cosmwasm compiler.
  2. The attacker deploys the contract to the chain
  3. The chain will allow the upload as the requires_* string is not present.
  4. The attacker can execute any action on the chain.

Workarounds

None known. capabilities should be checked at runtime too. In particular, the DefaultMessageHandler should check for a capability before dispatching a message.

Impact

A blockchain that leverages Capabilities restrictions to prevent contracts from executing specific actions is open to attacks. The severity of the impact on Integrity and Availability depends on the particular features of the blockchain's implementation, and this impact can potentially be critical.

The original report as published on HackerOne, by julianor. Images and videos are our own copies; raw HTML is shown as text. View it on HackerOne.

Written with AI from the full original report and checked against it passage by passage; anything it could not back up was removed or toned down. The original is the record. 4 min read.

Context

CosmWasm is a smart contract platform used by Cosmos chains. One of its features is the capability system: a contract declares the capabilities it requires, and the chain declares the capabilities it offers. The idea is that a chain can refuse to run contracts that need features the chain does not want to expose.

The report quotes the description in CAPABILITIES.md (https://github.com/CosmWasm/cosmwasm/blob/main/docs/CAPABILITIES.md):

Text
The contract defines required capabilities. The environment defines its capabilities. If the required capabilities are all available, the contract can be used.

The researcher's claim is that this description is misleading and that the implementation is naive: a contract can use a capability even when the chain has not made it available. The result is that an attacker can deploy a cosmwasm contract on a chain and execute any action on that chain, even when the executing chain does not allow that capability.

Setup

The scenario assumes two things about the target chain:

  1. The chain announced no capabilities, in order to disallow contracts from executing certain paths.
  2. The chain still allows users to execute those paths through regular, non-wasm messages.

The attacker needs to be able to build and deploy a contract to the chain. The report does not describe any accounts, roles, tool versions or other preconditions beyond this.

Finding it

The capability check is not enforced where it matters. The documentation says a contract can only be used if all its required capabilities are available, but the researcher shows that a capability can be used even when it is not available.

The gap is in how the requirement is expressed. The contract carries a requires_* string, and the chain decides whether to accept the upload based on whether that string is present. If the string is absent, the chain has nothing to check against and accepts the contract. The capability is not checked at the point where a message is actually dispatched.

Exploitation

Step 1: Remove the capability string from the compiler output

The attacker comments out the generation of the capabilities string in the cosmwasm compiler, at packages/std/src/exports.rs (the report links to commit [redacted]):

Text
https://github.com/CosmWasm/cosmwasm//blob/[redacted]/packages/std/src/exports.rs#L40

With that generation commented out, the compiled contract no longer carries the requires_* string that would declare which capabilities it needs.

Step 2: Deploy the contract to the chain

The attacker uploads the modified contract to the target chain.

Step 3: The chain accepts the upload

The chain allows the upload because the requires_* string is not present. There is no declared requirement for the chain to compare against its own capability list, so the check passes.

Step 4: Execute any action

With the contract deployed, the attacker can execute any action on the chain, including the paths the chain intended to keep out of reach of contracts by announcing no capabilities.

Root cause

The capability requirement is carried by the contract itself, in the requires_* string, and the chain only inspects that string when the contract is uploaded. An attacker who controls the compilation of the contract can simply omit the string, and the upload check has nothing to reject.

The capability is never checked at runtime. In particular, the DefaultMessageHandler dispatches messages without checking for a capability first. The upload check on requires_* does not stop the attack because the value it inspects is supplied by the attacker.

Impact

A blockchain that relies on Capabilities restrictions to prevent contracts from executing specific actions is open to attack. The severity of the impact on Integrity and Availability depends on the particular features of the blockchain's implementation, and the report states that this impact can potentially be critical.

The platform recorded the report as low severity, with a bounty of 2000.00 USD, under the weakness Privilege Escalation, on the CosmWasm asset.

Fix

The report lists no known workarounds. It recommends that capabilities should be checked at runtime too, and specifically that the DefaultMessageHandler should check for a capability before dispatching a message.

Variants to test

  • Deploy a contract with the capability declaration removed and attempt an action the chain meant to block for contracts. A positive result is the action succeeding from the contract even though the chain announced no such capability.
  • Compare the same action sent as a regular non-wasm message and from a contract. If both succeed, the capability restriction is not being enforced at dispatch time.
  • Look for other checks that rely on a value embedded in the uploaded artefact rather than on server-side state. A positive result is an upload being accepted because the declaring field is absent rather than because the requirement was satisfied.

Hunting notes

This kind of bug hides wherever a security decision is based on metadata supplied by the party being restricted, and where the enforcement happens once, at upload or registration time, rather than at the point of use. During recon, the signal is documentation that describes a guarantee (here, that a contract can only be used if its required capabilities are available) alongside an implementation that only reads a self-declared string. The researcher showed impact by taking the documented guarantee and removing the declaration the check depends on.

Written with AI from the full original report and checked against it passage by passage; anything it could not back up was removed or toned down. The original is the record. 10 min read.

What happened, in plain words

CosmWasm is a platform for running small programs, called smart contracts, on blockchains built with Cosmos. A blockchain is a shared record book that many computers keep in sync, and a smart contract is a program that lives on that chain and runs automatically when someone asks it to. CosmWasm gives those contracts a feature called capabilities. A capability is a permission: something a contract is allowed to do, such as reaching a particular part of the chain. The idea is simple. A contract writes down which permissions it needs, and the chain writes down which permissions it offers. If the contract needs something the chain does not offer, the chain should refuse to run it.

The researcher found that this promise does not hold. An attacker can deploy a contract on a chain and then make that contract perform any action on the chain, even an action the chain deliberately tried to keep away from contracts. The problem is that the permission list is written by the contract itself, and the chain only looks at that list once, when the contract is uploaded. If the attacker simply leaves the list out, the chain has nothing to compare against and lets the contract in. After that, nothing checks permissions again when the contract actually does something.

The report calls the implementation naive and the documentation misleading. It was filed against CosmWasm, recorded as low severity under the weakness Privilege Escalation, and paid a bounty of 2000.00 USD.

The product and the feature

CosmWasm is a smart contract platform used by Cosmos chains. Think of a chain as a public noticeboard that many independent computers maintain together, and a smart contract as a vending machine bolted to that noticeboard: anyone can press a button, and the machine follows its programmed rules without a human in the middle.

The feature at the centre of the report is the capability system. A capability is a named permission. The contract declares the capabilities it requires, and the chain declares the capabilities it offers. The intended behaviour is that a chain can refuse to run contracts that need features the chain does not want to expose. For example, a chain might decide that contracts are not allowed to reach a certain internal path, and it expresses that decision by announcing no capability for it.

The report quotes the description in CAPABILITIES.md (https://github.com/CosmWasm/cosmwasm/blob/main/docs/CAPABILITIES.md):

Text
The contract defines required capabilities. The environment defines its capabilities. If the required capabilities are all available, the contract can be used.

In plain words, this says: the contract lists what it needs, the chain lists what it has, and the contract is only usable when everything it needs is present. The researcher's claim is that this description is misleading and that the implementation is naive, because a contract can use a capability even when the chain has not made it available.

The setup the attack assumes

The scenario assumes two things about the target chain:

  1. The chain announced no capabilities, in order to disallow contracts from executing certain paths.
  2. The chain still allows users to execute those paths through regular, non-wasm messages.

A message here is simply an instruction sent to the chain, the way a click sends an instruction to a website. A non-wasm message is an ordinary instruction that comes from a user rather than from a contract. So the chain is saying two different things: contracts may not touch these paths, but ordinary users may. That difference is what makes the attack interesting, because the attacker wants a contract to do what only a user is supposed to be able to do.

The attacker also needs to be able to build and deploy a contract to the chain. Building means turning the contract's source code into the finished program that the chain will run, and deploying means uploading that finished program to the chain. The report does not describe any accounts, roles, tool versions or other preconditions beyond this.

Finding it

The capability check is not enforced where it matters. The documentation says a contract can only be used if all its required capabilities are available, but the researcher shows that a capability can be used even when it is not available.

The gap is in how the requirement is expressed. The contract carries a requires_* string, and the chain decides whether to accept the upload based on whether that string is present. A string is just a piece of text. The requires_* string is the contract's written-down list of permissions it needs. If the string is absent, the chain has nothing to check against and accepts the contract. The capability is therefore only enforced at upload time, through a value the attacker controls, and not at the point where a message is actually dispatched.

Dispatching a message means handing it to the part of the system that carries it out. That moment, when the action actually happens, is where a permission check would be meaningful, because that is the moment the forbidden thing would occur. Checking only at upload time is like a bouncer who reads your name off a form you filled in yourself and never looks at you again once you are inside.

Exploitation

Step 1: Remove the capability string from the compiler output

The attacker comments out the generation of the capabilities string in the cosmwasm compiler, at packages/std/src/exports.rs (the report links to commit [redacted]):

Text
https://github.com/CosmWasm/cosmwasm//blob/[redacted]/packages/std/src/exports.rs#L40

A compiler is the tool that turns source code into a runnable program. Commenting out a line means marking it so the compiler ignores it, without deleting it. The line in question is the one that produces the capability string, so once it is commented out, the compiled contract no longer carries the requires_* string that would declare which capabilities it needs. The attacker does this because the chain's only check depends on that string being there. Remove the declaration, and the check has nothing to inspect.

Step 2: Deploy the contract to the chain

The attacker uploads the modified contract to the target chain. Uploading is the act of sending the finished program to the chain so that it can be stored and later run. The attacker does this because the whole point is to get a contract onto the chain that the chain would otherwise have rejected.

Step 3: The chain accepts the upload

The chain allows the upload because the requires_* string is not present. There is no declared requirement for the chain to compare against its own capability list, so the check passes.

Step 4: Execute any action

With the contract deployed, the attacker can execute any action on the chain, including the paths the chain intended to keep out of reach of contracts by announcing no capabilities. In other words, the contract can reach actions the chain intended to keep away from contracts.

Root cause

The capability requirement is carried by the contract itself, in the requires_* string, and the chain only inspects that string when the contract is uploaded. An attacker who controls the compilation of the contract can simply omit the string, and the upload check has nothing to reject. This is a general pattern worth remembering: whenever a security decision is based on information supplied by the party being restricted, that party can usually shape the information to its advantage.

The capability is never checked at runtime. In particular, the DefaultMessageHandler dispatches messages without checking for a capability first. The DefaultMessageHandler is the component that takes a message and carries it out. Because it does not consult the capability list before acting, the forbidden action goes through. The existing defence, the upload-time check on requires_*, does not stop the attack because the value it inspects is supplied by the attacker.

Impact

A blockchain that relies on Capabilities restrictions to prevent contracts from executing specific actions is open to attack. The severity of the impact on Integrity and Availability depends on the particular features of the blockchain's implementation, and the report states that this impact can potentially be critical.

Integrity means the data and rules stay as they should, and Availability means the service keeps working for the people who need it. If a contract can reach paths the chain meant to protect, the impact depends on what those paths do on that particular chain. How bad it gets depends on what those paths actually do on that particular chain.

The platform recorded the report as low severity, with a bounty of 2000.00 USD, under the weakness Privilege Escalation, on the CosmWasm asset. Privilege escalation means getting more power than you were supposed to have.

Fix

The report lists no known workarounds. It recommends that capabilities should be checked at runtime too, and specifically that the DefaultMessageHandler should check for a capability before dispatching a message. In everyday terms, the bouncer should check your permission at the door of each room, not just read a form at the front entrance.

Variants to test

These are ways to look for the same kind of mistake elsewhere:

  • Deploy a contract with the capability declaration removed and attempt an action the chain meant to block for contracts. A positive result is the action succeeding from the contract even though the chain announced no such capability.
  • Compare the same action sent as a regular non-wasm message and from a contract. If both succeed, the capability restriction is not being enforced at dispatch time.
  • Look for other checks that rely on a value embedded in the uploaded artefact rather than on server-side state. A positive result is an upload being accepted because the declaring field is absent rather than because the requirement was satisfied.

Hunting notes

This kind of bug hides wherever a security decision is based on metadata supplied by the party being restricted, and where the enforcement happens once, at upload or registration time, rather than at the point of use. Metadata is data about data: here, the contract's own description of what it needs. During recon, the signal is documentation that describes a guarantee (here, that a contract can only be used if its required capabilities are available) alongside an implementation that only reads a self-declared string. The researcher showed impact by taking the documented guarantee and removing the declaration the check depends on.

Glossary

  • Blockchain: a shared record book kept in sync by many computers, where entries are hard to change after the fact.
  • Smart contract: a program that lives on a blockchain and runs automatically when someone sends it an instruction.
  • Cosmos: a family of blockchain networks and tools that can talk to each other.
  • CosmWasm: a smart contract platform used by Cosmos chains.
  • Capability: a named permission that a contract may need in order to do something on a chain.
  • Capability system: the arrangement where a contract declares the permissions it needs and the chain declares the permissions it offers.
  • requires_* string: the piece of text in a compiled contract that lists the capabilities it requires.
  • Compiler: the tool that turns source code into a runnable program.
  • Comment out: mark a line so the compiler ignores it, without deleting it.
  • Deploy / upload: send a finished contract program to a chain so it can be stored and run.
  • Message: an instruction sent to a chain.
  • Non-wasm message: an ordinary instruction sent by a user rather than by a contract.
  • Dispatch: hand a message to the part of the system that carries it out.
  • DefaultMessageHandler: the component that takes a message and carries it out.
  • Runtime: the moment a program is actually running, as opposed to when it is uploaded or built.
  • Upload-time check: a check performed once, when a contract is uploaded, rather than each time it acts.
  • Privilege escalation: gaining more power or access than you were supposed to have.
  • Integrity: the property that data and rules stay as they should and are not tampered with.
  • Availability: the property that a service keeps working for the people who need it.
  • Severity: a rating of how serious a security issue is.
  • Bounty: a payment made to a researcher who reports a valid security issue.
  • Metadata: data that describes other data, such as a contract's own description of what it needs.
  • Recon: the information-gathering phase before attempting an attack or a test.
  • Workaround: a temporary way to reduce the risk of an issue without fixing its root cause.

More from Cosmos

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Broken access control

The lesson behind this report.

A user can do something their role should not allow: reach an admin function, act on a feature they have not paid for, or skip a permission check. IDOR is the special case where the object belongs to someone else.