Back to skill

Security audit

Swap Integration

Security checks for vulnerabilities and agentic risk

Overview

This PancakeSwap integration skill is coherent, but its examples can grant persistent unlimited token approvals and send real swaps on mainnet.

Review generated code before running it with any funded wallet. Prefer testnet or simulation first, use exact-amount or short-lived approvals, verify router and Permit2 addresses, pin dependencies with a lockfile, and avoid placing production private keys in environments the agent or project tooling can read unnecessarily.

Vulnerability Patterns
  • Insecure DependenciesIntroduces malicious components through unsafe dependency sources
  • Insecure Skill Coding PracticesFinds exploitable flaws such as hardcoded secrets or command injection
  • Skill Instruction HijackingAlters the agent's session goals or safety constraints when the skill loads
  • Agent Memory PoisoningWrites attacker-controlled rules into memory that affect later sessions
  • Remote Payload Retrieval and ExecutionFetches external code whose behavior can change after review
Findings (2)

T09 · Insecure Skill Coding Practices

Error
Location
SKILL.md:369
Finding

Persistent Unlimited Token Allowances Expand the Asset-Transfer Attack Surface

Content
View full analysis

Vulnerability Details

File Location: SKILL.md, lines 369–399
Vulnerability Type: Persistent and excessive token authorization
Risk Level: High

Vulnerable Code

typescript
const MAX_UINT256 = BigInt('0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff')
if (permit2Allowance < MAX_UINT256 / 2n) {
  const hash = await walletClient.writeContract({
    address: tokenAddress,
    abi: erc20Abi,
    functionName: 'approve',
    args: [PERMIT2_ADDRESS, MAX_UINT256],
  })
  await publicClient.waitForTransactionReceipt({ hash })
  console.log('✅ Permit2 approved')
}

// Step 2: Approve the Universal Router via Permit2 (per-swap, via signature OR transaction)
// The Universal Router SDK handles this via inputTokenPermit in options.
// For simplicity, approve the Universal Router directly instead:
const routerAddress = getUniversalRouterAddress(chainId) as `0x${string}`
const routerAllowance = await publicClient.readContract({
  address: tokenAddress,
  abi: erc20Abi,
  functionName: 'allowance',
  args: [owner, routerAddress],
})

if (routerAllowance < MAX_UINT256 / 2n) {
  const hash = await walletClient.writeContract({
    address: tokenAddress,
    abi: erc20Abi,
    functionName: 'approve',
    args: [routerAddress, MAX_UINT256],
  })
  await publicClient.waitForTransactionReceipt({ hash })
  console.log('✅ Universal Router approved')
}

Technical Analysis

The example grants the maximum possible ERC-20 allowance to both Permit2 and the Universal Router. These authorizations are substantially broader than the amount required for an individual swap and can remain valid after the swap completes.

Approving both Permit2 and the router also creates two independent authorization paths. This exceeds minimum privilege because a swap can instead use an exact-amount approval or a constrained Permit2 authorization. The code only checks whether the ...[truncated 1625 chars]

Remediation
View remediation

Remediation Suggestions

  1. Approve only the exact input amount required for the pending swap.
  2. Prefer a Permit2 signature constrained by token, exact amount, spender, chain ID, nonce, and a short expiration time.
  3. Do not approve both Permit2 and the Universal Router unless the selected integration explicitly requires both authorization paths.
  4. Present the spender address, allowance amount, chain, and expiration to the user before requesting authorization.
  5. Validate router and Permit2 addresses against a chain-specific, audited allowlist.
  6. Provide an allowance-revocation workflow and recommend revoking unused persistent approvals.
  7. If an unlimited approval remains available as an opt-in convenience, clearly warn that it is persistent and can expose the token's entire wallet balance.

T08 · Insecure Dependencies

Warning
Location
SKILL.md:219
Finding

Mutable npm Dependencies Are Installed Without Exact Version Pinning

Content
View full analysis

Vulnerability Details

File Location: SKILL.md, line 219
Vulnerability Type: Unpinned third-party executable dependencies
Risk Level: Medium

Vulnerable Code

bash
npm install @pancakeswap/smart-router @pancakeswap/sdk @pancakeswap/v3-sdk @pancakeswap/universal-router-sdk viem@2.37.13

Technical Analysis

Only viem is pinned to an exact version. The PancakeSwap packages are installed using npm's current default versions, so the effective code can change after the Skill has been reviewed. This prevents a consumer from reliably reproducing the audited dependency set.

These packages participate in pool discovery, route selection, allowance handling, address resolution, and transaction-calldata construction. A malicious, compromised, or incompatible future release could therefore affect wallet-facing security decisions. Package installation may also execute package lifecycle scripts under the privileges of the user running npm.

The audit did not establish that the named packages are currently malicious. The vulnerability is the mutable and insufficiently controlled dependency resolution documented by the Skill.

Attack Path

  1. An attacker compromises a listed package, its publisher account, or its release pipeline and publishes a malicious version under the legitimate package name.
  2. A user later executes the documented npm install command.
  3. npm resolves an unpinned package to the compromised release.
  4. Malicious code executes through an installation lifecycle hook or when the application imports and uses the package.
  5. Depending on the compromised component, the code could access process-readable data, alter approval or transaction parameters, substitute contract addresses, or generate attacker-benefiting calldata before the user signs a transaction.

Impact Assessment

Installation-time code runs with the permissions of the account executing npm and may access project files, e ...[truncated 479 chars]

Remediation
View remediation

Remediation Suggestions

  1. Pin every dependency to a reviewed exact version rather than a tag or version range.
  2. Commit a generated lockfile and use npm ci in automated and reproducible installations.
  3. Review lockfile integrity hashes and package provenance before release.
  4. Disable lifecycle scripts where they are unnecessary, such as with npm ci --ignore-scripts, and explicitly document any packages that require them.
  5. Run dependency auditing, software-composition analysis, and registry provenance verification in CI.
  6. Use a trusted registry configuration and protect against dependency substitution or registry override.
  7. Test upgrades separately and require security review before updating wallet, routing, or transaction-encoding dependencies.
Vulnerability Patterns
  • Prompt InjectionInstruction Override, Hidden Instructions, Exfiltration Commands
  • Data ExfiltrationExternal Transmission, Env Variable Harvesting, File System Enumeration
  • Excessive AgencyUnrestricted Tool Access, Autonomous Decision Making, Scope Creep
  • Trigger AbuseOverly Broad Trigger, Shadow Command Trigger, Keyword Baiting Trigger
  • Privilege EscalationExcessive Permissions, Sudo/Root Execution, Credential Access
Findings (5)

Vague Triggers

Medium
Category
Not specified by scanner
Confidence
94% confidence
Finding

The trigger phrases are broad enough to activate on generic requests like 'create a swap script' or 'add swap functionality', which can route users into a high-risk skill that includes token approvals and live transaction flows. In this context, over-broad activation increases the chance of accidental invocation for unrelated or non-PancakeSwap tasks, exposing users to unsafe financial guidance or unintended fund-moving instructions.

Content

No source excerpt is available for this finding.

External Model or Provider Selection

Medium
Category
Excessive Agency
Confidence
90% confidence
Finding

Skill selects an external model or provider that may use a different account or billing plan than the operator expects. Undisclosed model switches can cause unexpected cost or quota consumption.

Content

Scanner excerpt · SKILL.md (reported line 7)May include surrounding context.

md
description: Integrate PancakeSwap swaps into applications. Use when user says "integrate swaps", "pancakeswap", "smart router", "add swap functionality", "build a swap frontend", "create a swap script", "smart contract swap integration", "use Universal Router", or mentions swapping tokens via PancakeSwap.
homepage: https://github.com/pancakeswap/pancakeswap-ai
allowed-tools: Read, Write, Edit, Glob, Grep, Bash(npm:*), Bash(npx:*), Bash(yarn:*), Bash(curl:*), WebFetch, Task(subagent_type:swap-integration-expert)
model: opus
license: MIT
metadata:
  author: pancakeswap

Missing User Warnings

Medium
Category
Not specified by scanner
Confidence
97% confidence
Finding

The skill provides concrete approval and transaction-sending instructions without an upfront warning that the examples can grant spending permissions and move real assets on mainnet. In a crypto integration skill, this omission is especially dangerous because users may copy-paste code that approves unlimited allowances or broadcasts live swaps without understanding the financial consequences.

Content

No source excerpt is available for this finding.

Whitespace Padding

Medium
Category
Prompt Injection
Confidence
70% confidence
Finding

Large whitespace padding was detected (a block of blank lines or a long run of spaces). This can push injected instructions below or to the right of the visible area so a human reviewer never sees them while the agent still reads them. Manual review of the hidden content is recommended.

Content

Scanner excerpt · SKILL.md (reported line 56)May include surrounding context.

md
### Protocol Types

| Protocol     | Description                                                                                      | Fee Tiers (bps)         | Chains        |
| ------------ | ------------------------------------------------------------------------------------------------ | ----------------------- | ------------- |
| V2           | Classic AMM (xy=k), constant product formula                                                     | 25 (0.25%)              | BSC only      |
| V3           | Concentrated liquidity (Uniswap V3-compatible)                                                   | 1, 5, 25, 100 (0.01–1%) | All chains    |

Autonomous Decision Making

Medium
Category
Excessive Agency
Confidence
75% confidence
Finding

Skill enables autonomous high-impact decisions without human-in-the-loop verification. Critical operations (destructive commands, financial transactions, data deletion) should require explicit user confirmation.

Content

Scanner excerpt · SKILL.md (reported line 608)May include surrounding context.

md
| Smart Router / Universal Router | Token → Permit2            | One-time per token       |
| Smart Router / Universal Router | Permit2 → Universal Router | Per session (or use sig) |
| Direct V2 Router                | Token → V2 Router          | One-time per token       |
| Native BNB/ETH input            | No approval needed         | —                        |

---

Static analysis

No suspicious patterns detected.