reconFTW is a tool designed to perform automated recon on a target domain by running the best set of tools to perform scanning and finding out vulnerabilities
id: 02-01 phase: 02 plan: 01 type: execute wave: 1 depends_on: [] requirements: [SEC-01] files_modified:
- lib/common.sh
- tests/unit/test_common.bats
- tests/integration/test_full_flow.bats
- CHANGELOG.md
- CLAUDE.md
- .planning/codebase/CONVENTIONS.md
- .planning/codebase/STRUCTURE.md
- .planning/codebase/ARCHITECTURE.md
autonomous: true
must_haves:
truths:
- "D-01:
safe_count()function definition (lib/common.sh:748-764) and its 17-line block (Usage comment + body) are entirely removed — no deprecation stub, no back-compat wrapper, no zero-caller function left behind" - "D-01:
grep -rn 'safe_count' . --include='*.sh' --include='*.bats'returns 0 hits after the change (function definition gone, 3 bats tests gone)" - "D-01:
count_lines()(lib/common.sh:125) andcount_lines_stdin()(lib/common.sh:136) remain untouched — they are the canonical replacement helpers and are already used by 11 callers in modules/" - "D-02: Two bats
@testblocks at tests/unit/test_common.bats:253-266 (including the# safe_count testssection banner) are deleted as one chunk — they exercise the eval pipeline branch and cannot be ported tocount_lines" - "D-02: One bats
@testblock at tests/integration/test_full_flow.bats:245-256 (the full-flowsafe_count handles missing filestest) is deleted —count_linesis already covered by sibling tests in test_common.bats" - "D-02: After deletion,
bats tests/unit/test_common.batsandbats tests/integration/test_full_flow.batsstill succeed (no syntax errors from dangling section headers or orphanedsetup/teardownblocks)" - "D-03: All 5 documentation files referencing
safe_count(CHANGELOG.md:203, CLAUDE.md:283, .planning/codebase/CONVENTIONS.md:~162-164, .planning/codebase/STRUCTURE.md:18, .planning/codebase/ARCHITECTURE.md:63) are updated in-place to drop thesafe_countmention or substitute thecount_linesequivalent" - "D-03:
.planning/PROJECT.md:46Active bullet for SEC-01 is NOT edited as part of this plan — it is the transition step's responsibility to move from Active → Validated" - "lib/common.sh source-guard
[[ -n \"$_COMMON_SH_LOADED\" ]] && return 0(line 6) is preserved; the blank line at lib/common.sh:747 and the# Pipeline Helperssection divider at lib/common.sh:766 are both preserved (only lines 748-764 are removed)" - "bash syntax check passes on lib/common.sh after deletion —
bash -n lib/common.shexits 0" artifacts: - path: "lib/common.sh" provides: "safe_count() function definition removed; count_lines/count_lines_stdin preserved" pattern_absent: "safe_count"
- path: "tests/unit/test_common.bats" provides: "safe_count test section + 2 @test blocks removed; surrounding sections intact" pattern_absent: "safe_count"
- path: "tests/integration/test_full_flow.bats" provides: "safe_count integration @test block removed" pattern_absent: "safe_count"
- path: "CHANGELOG.md" provides: "safe_count reference dropped from line ~203" pattern_absent: "safe_count"
- path: "CLAUDE.md" provides: "safe_count reference dropped from line ~283" pattern_absent: "safe_count"
- path: ".planning/codebase/CONVENTIONS.md" provides: "safe_count example block retitled or removed at line ~162-164" pattern_absent: "safe_count"
- path: ".planning/codebase/STRUCTURE.md" provides: "safe_count reference dropped from common.sh listing at line ~18" pattern_absent: "safe_count"
- path: ".planning/codebase/ARCHITECTURE.md" provides: "safe_count reference dropped from Component Responsibilities table at line ~63" pattern_absent: "safe_count" key_links:
- from: "callers in modules/*.sh" to: "lib/common.sh count_lines() / count_lines_stdin()" via: "direct file-path or stdin-pipe invocation" pattern: "count_lines"
- "D-01:
Delete `safe_count()` from `lib/common.sh` (function body + Usage comment block at :748-764), its 3 bats tests, and 5 doc-file references. Closes SEC-01 by removing the latent `eval` injection vector entirely rather than just trimming its `else` branch.
Purpose: lib/common.sh:760 runs eval "$1" when $1 is not a file path. Today there are zero live callers in lib/ or modules/ (verified via grep -rn 'safe_count' . --include='*.sh'); only the function definition itself and 3 bats tests reference it. The ROADMAP success criterion ("else branch is gone") is satisfied trivially by full deletion. Per CONTEXT.md D-01 and CLAUDE.md "if certain something is unused, delete it completely", we delete the whole function rather than leaving a zero-caller surface as a future trap. The 3 bats tests exercise the eval branch via pipeline-string form (safe_count "cat test.txt") and cannot be ported as-is; per D-02 they are deleted because count_lines is already covered elsewhere in test_common.bats.
Output: 17-line block removed from lib/common.sh; 14-line block + 12-line block removed from the two bats files; 5 documentation files updated in-place to drop the safe_count mention. Bash and bats syntax remain valid. The replacement helpers count_lines() and count_lines_stdin() (already living at lib/common.sh:125 and :136) remain untouched.
From lib/common.sh:122-140 (REPLACEMENT HELPERS — keep untouched):
# Count non-empty lines in a file safely
# Usage: count_lines filename
# Returns: line count (0 if file doesn't exist or is empty)
count_lines() {
local file="$1"
if [[ -s "$file" ]]; then
sed '/^$/d' "$file" | wc -l | tr -d ' '
else
echo 0
fi
}
# Count lines from stdin, with fallback to 0 on failure
# Usage: result=$(command | count_lines_stdin)
count_lines_stdin() {
local count
count=$(sed '/^$/d' | wc -l | tr -d ' ') || count=0
echo "${count:-0}"
}
From lib/common.sh:748-764 (BLOCK TO DELETE):
# Count non-empty lines in a file safely
# Usage: NUMOFLINES=$(safe_count "file_path")
# NUMOFLINES=$(safe_count "command | pipeline") # legacy: still supported via eval
# Always returns a valid number (0 on failure)
safe_count() {
local result
if [[ -f "$1" ]]; then
# Safe path: count lines in file directly, no eval
result=$(sed '/^$/d' "$1" 2>/dev/null | wc -l | tr -d ' ') || result=0
else
# Legacy fallback for callers passing pipeline strings
# TODO: migrate remaining callers to pass file paths
result=$(eval "$1" 2>/dev/null | sed '/^$/d' | wc -l | tr -d ' ') || result=0
fi
[[ "$result" =~ ^[0-9]+$ ]] || result=0
echo "$result"
}
From tests/unit/test_common.bats:253-266 (BLOCK TO DELETE):
###############################################################################
# safe_count tests
###############################################################################
@test "safe_count returns valid number" {
printf "line1\nline2\n" > test.txt
result=$(safe_count "cat test.txt")
[ "$result" -eq 2 ]
}
@test "safe_count returns 0 on failure" {
result=$(safe_count "cat nonexistent_file_xyz.txt")
[ "$result" -eq 0 ]
}
From tests/integration/test_full_flow.bats:245-256 (BLOCK TO DELETE):
@test "full flow: safe_count handles missing files" {
source_reconftw
# shellcheck source=/dev/null
source "$SCRIPTPATH/lib/common.sh"
# Test with non-existent file
local count
count=$(safe_count "/nonexistent/file.txt")
[ "$count" -eq 0 ]
}
Task 1: Delete safe_count() from lib/common.sh + its 3 bats tests
lib/common.sh, tests/unit/test_common.bats, tests/integration/test_full_flow.bats
- lib/common.sh (current state — locate lines 748-764 containing the Usage comment block + function body; confirm the blank line at 747 and the `# Pipeline Helpers` divider at 766 frame the deletion)
- lib/common.sh:122-140 (the `count_lines` / `count_lines_stdin` replacement helpers — must remain untouched)
- tests/unit/test_common.bats:253-266 (the `safe_count tests` section header + 2 `@test` blocks; locate the trailing blank line before line 267 to determine the exact end-of-block)
- tests/integration/test_full_flow.bats:245-256 (the `full flow: safe_count handles missing files` test; check siblings at :234-243 and :257+ for the surrounding blank-line spacing pattern)
- .planning/phases/02-security-quoting-supply-chain-hygiene/02-CONTEXT.md sections "D-01" and "D-02"
- .planning/phases/02-security-quoting-supply-chain-hygiene/02-PATTERNS.md sections "lib/common.sh:748-764", "tests/unit/test_common.bats:253-266", "tests/integration/test_full_flow.bats:245-256"
Per D-01: in lib/common.sh, delete the 17-line block from line 748 through line 764 inclusive — that block contains the 4-line Usage comment (`# Count non-empty lines in a file safely` / `# Usage: NUMOFLINES=...` / `# NUMOFLINES=...` / `# Always returns a valid number...`) followed by the `safe_count()` function body (`safe_count() { ... }`) and its closing `}` brace. Preserve the blank line at line 747 (separator between `run_with_heartbeat_shell` end and the `safe_count` doc comment) AND preserve the section divider beginning at line 766 (`###############################################################################` followed by `# Pipeline Helpers`). The source-guard at line 6 (`[[ -n "$_COMMON_SH_LOADED" ]] && return 0`) is untouched.
Per D-02: in tests/unit/test_common.bats, delete the entire 14-line block from line 253 through line 266 inclusive — that comprises the 3-line section banner (`#####...`, `# safe_count tests`, `#####...`), a blank line, two `@test` blocks (`safe_count returns valid number`, `safe_count returns 0 on failure`), and the trailing blank line before line 267 (`# process_results tests` banner). Do NOT leave a dangling section header.
Per D-02: in tests/integration/test_full_flow.bats, delete the entire 12-line block from line 245 through line 256 inclusive — that is the `@test "full flow: safe_count handles missing files" { ... }` block plus the blank line that follows. Sibling `@test` blocks at :234-243 and :257+ remain untouched.
Do NOT port the deleted tests to `count_lines`-form: per CONTEXT.md D-02, `count_lines` is already covered by sibling tests in test_common.bats, so porting would add no new coverage.
bash -n lib/common.sh && grep -rn 'safe_count' lib/ modules/ tests/ --include='*.sh' --include='*.bats' | wc -l | tr -d ' '
- `bash -n lib/common.sh` exits 0 (no syntax error from incomplete deletion)
- `grep -rn 'safe_count' lib/ modules/ tests/ --include='*.sh' --include='*.bats' | wc -l | tr -d ' '` returns `0`
- `grep -n 'safe_count' lib/common.sh` returns 0 hits
- `grep -n 'safe_count' tests/unit/test_common.bats` returns 0 hits
- `grep -n 'safe_count' tests/integration/test_full_flow.bats` returns 0 hits
- `grep -n '# Pipeline Helpers' lib/common.sh` returns exactly 1 hit (the section divider after the deleted block is preserved)
- `grep -nE '^count_lines\(\)' lib/common.sh` returns 1 hit (the file-path helper at :125 is preserved)
- `grep -nE '^count_lines_stdin\(\)' lib/common.sh` returns 1 hit (the stdin helper at :136 is preserved)
- `bash -c 'source lib/common.sh; type count_lines >/dev/null && type count_lines_stdin >/dev/null'` exits 0 (helpers still callable post-deletion)
- `bats tests/unit/test_common.bats` reports zero "syntax error" / "command not found" output (full pass not required from this task — the deleted tests were the only safe_count callers; remaining tests are unrelated to this change)
lib/common.sh has no `safe_count` definition; tests/unit/test_common.bats has no `# safe_count tests` section and no safe_count `@test`; tests/integration/test_full_flow.bats has no safe_count `@test`; bash syntax intact; replacement helpers `count_lines`/`count_lines_stdin` callable.
Task 2: Update 5 doc files to drop safe_count references
CHANGELOG.md, CLAUDE.md, .planning/codebase/CONVENTIONS.md, .planning/codebase/STRUCTURE.md, .planning/codebase/ARCHITECTURE.md
- CHANGELOG.md (locate the line referencing `count_lines()` / `safe_count()` around line 203)
- CLAUDE.md (locate the line in the Architecture / Common section referencing `safe_count` around line 283)
- .planning/codebase/CONVENTIONS.md (locate the `**safe_count()** in lib/common.sh` example block around lines 162-164)
- .planning/codebase/STRUCTURE.md (locate the `common.sh` directory listing line referencing `safe_count` around line 18)
- .planning/codebase/ARCHITECTURE.md (locate the Component Responsibilities table row for `lib/common.sh` around line 63 referencing `safe_count`)
- .planning/phases/02-security-quoting-supply-chain-hygiene/02-CONTEXT.md section "D-03"
- .planning/phases/02-security-quoting-supply-chain-hygiene/02-PATTERNS.md "Doc reference updates (Plan 02-01 / D-03)" table
Per D-03 (mechanical text substitution in 5 files; precise per-file edits):
1. CHANGELOG.md line ~203 — replace the bullet text `` - `count_lines()`/`safe_count()` `` with `` - `count_lines()` `` (drop the `/safe_count()` slash-paired alternative). If the actual on-disk text differs from this exact form (e.g., spacing variation), preserve the surrounding sentence structure and just remove the `safe_count` token + its separator.
2. CLAUDE.md line ~283 — locate the prose mentioning `... count_lines, safe_count, incident tracking ...` and remove `, safe_count` so the list reads `... count_lines, incident tracking ...`.
3. .planning/codebase/CONVENTIONS.md around lines 162-164 — the current block reads (per phase patterns):
```
**`safe_count()`** in `lib/common.sh` — always returns a valid integer:
```bash
NUMOFLINES=$(safe_count "subdomains/subdomains.txt") # preferred: direct file path
```
Falls back to `eval` for legacy pipeline strings (marked TODO for migration).
```
Replace the entire block with:
```
**`count_lines()`** in `lib/common.sh` — counts non-empty lines in a file; returns 0 if missing or empty:
```bash
NUMOFLINES=$(count_lines "subdomains/subdomains.txt")
```
For stdin-pipe inputs, use `count_lines_stdin` (e.g., `result=$(some_cmd | count_lines_stdin)`).
```
Match the existing CONVENTIONS.md heading-style; do not introduce new section banners.
4. .planning/codebase/STRUCTURE.md line ~18 — replace `│ ├── common.sh # File/dir helpers, incident tracking, count_lines, safe_count` with `│ ├── common.sh # File/dir helpers, incident tracking, count_lines` (drop `, safe_count`).
5. .planning/codebase/ARCHITECTURE.md line ~63 — in the Component Responsibilities table row for `Shared file/counter utilities`, change the responsibility cell from `\`ensure_dirs\`, \`ensure_webs_all\`, \`safe_backup\`, \`count_lines\`, \`safe_count\`, incident tracking` to `\`ensure_dirs\`, \`ensure_webs_all\`, \`safe_backup\`, \`count_lines\`, incident tracking` (drop `, \`safe_count\``).
Per CONTEXT.md D-03 explicit exclusion: do NOT edit `.planning/PROJECT.md:46` — the SEC-01 Active → Validated transition is the responsibility of the post-phase transition step, not this plan.
Per CONTEXT.md Claude's Discretion: bundle these 5 edits in the same commit as Task 1, OR split them into a follow-up commit — either is acceptable. Recommend a single commit (`docs(02-01): drop safe_count references`) bundled with Task 1 for atomic remediation.
grep -c 'safe_count' CHANGELOG.md CLAUDE.md .planning/codebase/CONVENTIONS.md .planning/codebase/STRUCTURE.md .planning/codebase/ARCHITECTURE.md | awk -F: '{sum+=$2} END {print sum}'
- `grep -c 'safe_count' CHANGELOG.md CLAUDE.md .planning/codebase/CONVENTIONS.md .planning/codebase/STRUCTURE.md .planning/codebase/ARCHITECTURE.md | awk -F: '{sum+=$2} END {print sum}'` returns `0`
- `grep -n 'count_lines' .planning/codebase/STRUCTURE.md` still returns at least 1 hit (the replacement reference is present)
- `grep -n 'count_lines' .planning/codebase/ARCHITECTURE.md` still returns at least 1 hit (the replacement reference is present)
- `grep -n 'count_lines' CHANGELOG.md` still returns at least 1 hit
- `grep -n 'count_lines' .planning/codebase/CONVENTIONS.md` returns at least 1 hit (the replacement block uses `count_lines` as the title)
- `grep -n 'safe_count' .planning/PROJECT.md` returns whatever was there before (this plan does NOT edit PROJECT.md — exclusion per D-03)
- `grep -rn 'safe_count' . --include='*.md' --exclude-dir=node_modules --exclude-dir=.git | grep -v '/.planning/phases/02-' | wc -l | tr -d ' '` returns `0` (no doc files outside the 02-* phase planning artefacts still reference safe_count)
5 doc files have zero `safe_count` matches; replacement `count_lines` references are present where appropriate; .planning/PROJECT.md unmodified by this plan.
## Trust Boundaries
| Boundary | Description |
|---|---|
| internal helper → eval | safe_count() accepts a string arg; the else branch executes the string via eval |
| caller intent → callee form | Callers passed either a file path (safe branch) or a pipeline string (eval branch). Same function signature, two semantically distinct trust postures. |
STRIDE Threat Register
| Threat ID | Category | Component | Disposition | Mitigation Plan |
|---|---|---|---|---|
| T-02-01-01 | E (Elevation of Privilege) | safe_count() eval branch at lib/common.sh:760 |
mitigate | Function deletion (D-01) removes the surface entirely. No opt-in, no deprecation stub — the eval branch is gone because the function is gone. |
| T-02-01-02 | E (Elevation of Privilege) | Future re-introduction of a safe_count-shaped helper |
mitigate | Doc updates (D-03) remove all 5 references that documented the previous "safe_count is the way" pattern. CONVENTIONS.md now documents count_lines/count_lines_stdin as the canonical helpers, steering future contributors away from any string-eval shape. |
| T-02-01-03 | T (Tampering) | bats tests at test_common.bats:253-266 / test_full_flow.bats:245-256 | mitigate | Test deletion (D-02) is required because the tests literally pass pipeline-strings (safe_count "cat test.txt") — keeping them would force the function to remain, blocking remediation. count_lines has independent coverage elsewhere in test_common.bats. |
| T-02-01-04 | R (Repudiation) | Documentation drift between code and docs | accept | The 5 doc edits (D-03) close the drift window. Future drift would require a new contribution to re-introduce the term. |
| T-02-01-05 | I (Information Disclosure) | eval-driven log expansion of attacker-controlled input |
mitigate | Same as T-02-01-01: function deletion eliminates the surface. No log path could ever again pass attacker-controlled data through eval. |
Residual risk: None within this plan's scope. The only re-introduction vector is a future contributor proposing a similarly-shaped helper. CONVENTIONS.md / CLAUDE.md doc updates direct future authors to count_lines instead.