# GHSA-q4pp-j36h-3gqg: Minimal `basti` IAM Policy Allows Shell Access

> The minimal IAM policy for basti allows users to obtain shell access on the bastion host instead of just port forwarding, leading to privilege escalation.

- **Severity:** Not scored
- **Exploited in the wild:** Not known
- **Login needed:** Any signed-in user
- **Attackable:** Over the internet
- **Victim action needed:** Not needed
- **Fix available:** Yes
- **Published:** 24 Aug 2023

## What is GHSA-q4pp-j36h-3gqg?

GHSA-q4pp-j36h-3gqg is a missing authorization vulnerability in basti-cdk, published on 24 Aug 2023. Any signed-in user can exploit it over the network, with no action from the victim.

### Official description

### Summary

The provided Minimal IAM Policy for `bastic connect` does not include `ssm:SessionDocumentAccessCheck`. This results in the ability to get a shell session on the bastion, not just the intended access for Port Forwarding.

### Details

`basti connect` is designed to "securely connect to your RDS/Aurora/Elasticache/EC2 instances", using a bastion instance "with [AWS Session Manager](https://docs.aws.amazon.com/systems-manager/latest/userguide/session-manager.html) port forwarding capability to make the target available on your localhost."

The [Minimal IAM Policy](https://github.com/BohdanPetryshyn/basti#minimal-iam-permissions) allows port forwarding via the following statement:

```   
 {
      "Effect": "Allow",
      "Action": "ssm:StartSession",
      "Resource": [
        "arn:aws:ssm:*:*:document/AWS-StartPortForwardingSessionToRemoteHost",
        "arn:aws:ec2:<your-region>:<your-account-id>:instance/<your-basti-instance-id>"
      ]
    }
```

This statement does not include the following condition:

```
"Condition": {
    "BoolIfExists": {
        "ssm:SessionDocumentAccessCheck": "true"
    }
}
```

As a result, the `basti connect` minimal policy is logically identical to:

```
 {
      "Effect": "Allow",
      "Action": "ssm:StartSession",
      "Resource": [
        "arn:aws:ssm:*:*:document/AWS-StartPortForwardingSessionToRemoteHost",
        "arn:aws:ssm:*:*:document/SSM-SessionManagerRunShell",
        "arn:aws:ec2:<your-region>:<your-account-id>:instance/<your-basti-instance-id>"
      ]
    }
```

A `basti` admin would expect users under the minimal policy to be able to port forward. However, they could also get a shell on the bastion.

For more details on this footgun, see: https://ramimac.me/ssm-iam

### PoC
_Complete instructions, including specific configuration details, to reproduce the vulnerability._

### Impact

Impact would depend on configuration/hardening of the bastion. I've seen examples where bastions have credentials to downstream systems in configuration or memory that would be exposed.

## Which versions are affected by GHSA-q4pp-j36h-3gqg?

2 open source packages ship an affected version, including basti-cdk.


| Package | Ecosystem | Affected | Fixed in |
| --- | --- | --- | --- |
| `basti-cdk` | npm | All versions | 1.0.1 |
| `basti-cdk` | npm | All versions | 1.0.1 |

## How do I fix GHSA-q4pp-j36h-3gqg?

Upgrade basti-cdk to 1.0.1 or later.

## Is GHSA-q4pp-j36h-3gqg being exploited?

There is no known exploitation of GHSA-q4pp-j36h-3gqg in the wild and no public exploit code.

## Fix prompt for AI coding agents

```text
Check this codebase for GHSA-q4pp-j36h-3gqg and fix it if it is affected.

What it is: GHSA-q4pp-j36h-3gqg is a missing authorization vulnerability in basti-cdk, published on 24 Aug 2023. Any signed-in user can exploit it over the network, with no action from the victim.
Exploitation: There is no known exploitation of GHSA-q4pp-j36h-3gqg in the wild and no public exploit code.

Affected packages and fixed versions:
- basti-cdk (npm): affected all versions; fixed in 1.0.1
- basti-cdk (npm): affected all versions; fixed in 1.0.1

Task:
1. Search the dependency manifests and lockfiles (for example package.json, package-lock.json, requirements.txt, poetry.lock, uv.lock, pom.xml, build.gradle, go.mod, Cargo.lock, Gemfile.lock) and any Dockerfiles for the affected packages, including transitive dependencies.
2. If an affected version is in use, upgrade it to the fixed version for its release line with the project's package manager, so the lockfile is regenerated. Prefer the smallest upgrade that fixes it.
3. If there is no fix, or the upgrade would break the build, do not guess: explain the risk and the safest workaround instead.
4. Run the tests and summarise what changed and why.
5. If nothing in the project is affected, say so and change nothing.

Reference: https://insights.sbomify.com/GHSA-q4pp-j36h-3gqg/ (Markdown: https://insights.sbomify.com/GHSA-q4pp-j36h-3gqg/index.md)
```

## Sources

- OSV: https://osv.dev/vulnerability/GHSA-q4pp-j36h-3gqg

---
From sbomify Insights: https://insights.sbomify.com/GHSA-q4pp-j36h-3gqg/
Summaries are generated and may contain mistakes; the official description above is the record.
