Skip to content
Back to skills

Cf Tools Archive Tar Extract

BSecurity

Extract or list a tar archive (.tar/.gz/.bz2/.xz) with auto-detect and path-traversal protection. Trigger: /cf-tools-archive-tar-extract

  • 2 stars
  • 0 votes
  • 0 copies
  • 0 views
  • Added November 11, 2026
toolsgobash

Security analysis

B75/100
  • criticalAccesses sensitive system or user directories

Pro shows the line behind each finding and how to fix it

Scanned November 11, 2026

npx -y skills add pauldx/claudifying --skill cf-tools-archive-tar-extract --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Cf Tools Archive Tar Extract?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Cf Tools Archive Tar Extract
[![Security: B — Skills Directory](https://www.skillsdirectory.com/api/skills/pauldx-cf-tools-archive-tar-extract/badge)](https://www.skillsdirectory.com/skills/pauldx-cf-tools-archive-tar-extract)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: cf-tools-archive-tar-extract
description: "Extract or list a tar archive (.tar/.gz/.bz2/.xz) with auto-detect and path-traversal protection. Trigger: /cf-tools-archive-tar-extract"
trigger: /cf-tools-archive-tar-extract
version: 1.0.0
---

# /cf-tools-archive-tar-extract

Auto-detect compression and extract a tar archive. Defaults to LIST-ONLY (`-t`); the user must pass `--extract` to actually unpack — this prevents accidental tarbombs.

## Usage

```
/cf-tools-archive-tar-extract backup.tar.gz                  # list only (default)
/cf-tools-archive-tar-extract backup.tar.gz --extract        # actually extract
/cf-tools-archive-tar-extract backup.tar.gz --extract --to /tmp/restored
/cf-tools-archive-tar-extract backup.tar.xz --list           # explicit list
```

Arguments:
1. `archive` (required) — .tar, .tar.gz/.tgz, .tar.bz2/.tbz2, .tar.xz/.txz
2. `--extract` — actually extract (omit for list-only)
3. `--list` — explicit list mode (default behavior anyway)
4. `--to <dir>` — extraction destination (default: current directory)

## What You Must Do When Invoked

### Step 1 — Validate archive and pick decompression flag

```bash
ARCHIVE="$1"
[ -f "$ARCHIVE" ] || { echo "ERROR: archive not found: $ARCHIVE"; exit 1; }

case "$ARCHIVE" in
  *.tar.gz|*.tgz)   FLAG="-z" ;;
  *.tar.bz2|*.tbz2) FLAG="-j" ;;
  *.tar.xz|*.txz)   FLAG="-J" ;;
  *.tar)            FLAG="" ;;
  *)
    echo "ERROR: unrecognized tar extension: $ARCHIVE"
    echo "Supported: .tar .tar.gz .tgz .tar.bz2 .tbz2 .tar.xz .txz"
    exit 1
    ;;
esac
echo "Archive: $ARCHIVE  (decompress: ${FLAG:-none})"
```

### Step 2 — Validate entries for path traversal BEFORE extracting

```bash
# Always list first and refuse if any entry contains ".." or is absolute
ENTRIES=$(tar -t $FLAG -f "$ARCHIVE")
BAD=$(echo "$ENTRIES" | awk '/^\// || /(^|\/)\.\.(\/|$)/ { print }')

if [ -n "$BAD" ]; then
  echo "ERROR: archive contains unsafe entries (path traversal or absolute paths):"
  echo "$BAD" | head -10
  echo "Refusing to extract. Inspect manually with: tar -t $FLAG -f $ARCHIVE"
  exit 1
fi
COUNT=$(echo "$ENTRIES" | wc -l | tr -d ' ')
echo "Entries: $COUNT (safety check passed)"
```

### Step 3 — List or extract

```bash
MODE="${MODE:-list}"     # caller flips to "extract" via --extract
DEST="${DEST:-.}"

if [ "$MODE" = "list" ]; then
  echo "$ENTRIES" | head -200
  if [ "$COUNT" -gt 200 ]; then
    echo "... (showing 200 of $COUNT — pass --extract to unpack, or pipe full listing yourself)"
  fi
  exit 0
fi

mkdir -p "$DEST"
echo "Extracting to: $DEST"
tar -x $FLAG -f "$ARCHIVE" -C "$DEST"
```

### Step 4 — Report

```bash
echo "✅ Extracted $COUNT entries to $DEST"
echo "   Size: $(du -sh "$DEST" | awk '{print $1}')"
```

## Output Contract

```
## Tar extract
**Archive:**     <abs-path>
**Compression:** gzip | bzip2 | xz | none
**Mode:**        list | extract
**Destination:** <abs-path>  (only if extracting)
**Entries:**     <N>
**Total size:**  <human-readable>  (only if extracting)
```

## Gotchas

- **DEFAULT IS LIST-ONLY**: this is intentional. Many archives have unexpected top-level layouts; preview first. Document this clearly in user-facing help.
- **Path traversal**: entries containing `..` or starting with `/` are refused. Modern GNU tar has `--no-absolute-names` / `--paths-from`, but the explicit check here works on BSD tar too.
- **Symlink attacks**: a malicious archive can include `link -> /etc/passwd`. GNU tar with `--no-overwrite-dir` helps; deeper protection requires a sandbox (out of scope).
- **Auto-detect via extension only**: tar's `-a` flag auto-detects by magic bytes on GNU tar — not on BSD. Sticking to extensions keeps it portable.
- **Listing 100k+ entry archives**: truncate to 200 lines or it floods context. The full listing is one tar command away.
- **Mixed content (multiple top-level dirs)**: list mode reveals this; extraction creates them all in `--to` dir.

## Cross-Platform Notes

- **macOS / Linux / WSL**: same tar invocation works.
- **xz**: BSD tar links against libxz on modern macOS — works out of the box.
- For Windows native tar, prefer WSL — handling of permissions and symlinks is much more sensible.

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

View all in tools →

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.