Skip to content

fix: Repair broken batch-import file upload + validation - #27

Merged
daimpad merged 1 commit into
mainfrom
claude/fix-data-prep-errors-kJYpl
Jun 23, 2026
Merged

fix: Repair broken batch-import file upload + validation#27
daimpad merged 1 commit into
mainfrom
claude/fix-data-prep-errors-kJYpl

Conversation

@daimpad

@daimpad daimpad commented Jun 23, 2026

Copy link
Copy Markdown
Owner

🔴 Critical Bug: Batch-Import Upload Completely Broken

The batch-import preview never worked. wp_tempnam() always produces a file ending in .tmp, but parse_file() detected the format solely from the on-disk extension. Every upload therefore hit "Format nicht unterstützt" and failed silently.

Proof

.tmp file without original name:  success=false, error='Format nicht unterstützt'
.tmp file with original_name='upload.csv': success=true, count=1

Fixes

1. Core Bug Fix

  • parse_file() now accepts optional $original_name parameter for format detection
  • AJAX preview handler passes the original filename to parse_file()
  • Backward-compatible (parameter is optional)

2. Security Hardening (Preview Handler)

  • Validate upload by real file extension instead of browser-supplied (spoofable) MIME type
  • Add is_uploaded_file() verification before move_uploaded_file()
  • Properly wp_unslash()/sanitize_*() all $_FILES values
  • Replace unlink() with wp_delete_file()

3. Code Quality

  • Remove unused SESSION_KEY constant (PHPStan: classConstant.unused)
  • Remove dead is_array() branch after array_combine() (always true in PHP 8)
  • Add translators: comments and comment punctuation (PHPCS)

Verification

  • ✅ PHPCS: 0 errors (5 warnings: local file I/O + custom capability expected)
  • ✅ PHPStan: No errors
  • ✅ PHPUnit: 90 tests pass

Files Changed

  • includes/class-batch-import.php: +15 lines (fix + code quality)
  • includes/class-admin.php: +19 lines (security hardening)

🤖 Generated with Claude Code


Generated by Claude Code

Critical bug: The batch-import preview never worked. wp_tempnam() always
produces a file ending in .tmp, but ODW_Batch_Import::parse_file() detected
the format solely from the on-disk extension. Every upload therefore hit
'Format nicht unterstützt (nur CSV oder JSON)' and failed.

Fixes:
- parse_file() now accepts an optional $original_name used for format
  detection, so temporary .tmp uploads are correctly recognised as CSV/JSON.
  The parameter is optional and backward-compatible.
- AJAX preview handler passes the original filename to parse_file().

Security hardening (preview handler):
- Validate the upload by its real file extension instead of the browser-
  supplied MIME type, which is trivially spoofable.
- Verify the upload with is_uploaded_file() before moving it.
- Properly wp_unslash()/sanitize $_FILES values.
- Replace unlink() with wp_delete_file().

Code quality:
- Remove unused SESSION_KEY constant (PHPStan: classConstant.unused).
- Remove dead is_array() branch after array_combine (always true in PHP 8).
- Add translators: comments and comment punctuation (PHPCS: 0 errors).

Verified: a .tmp file with original name 'upload.csv' now parses to 1 record;
previously returned 'Format nicht unterstützt'. Full suite: 90 tests pass,
PHPStan clean, PHPCS 0 errors.

https://claude.ai/code/session_01JB1xUQM892bVZ4Yv3MZjvq
@daimpad
daimpad merged commit 51af8a3 into main Jun 23, 2026
8 of 10 checks passed
@daimpad
daimpad deleted the claude/fix-data-prep-errors-kJYpl branch June 23, 2026 05:51
daimpad added a commit that referenced this pull request Jun 27, 2026
Bump version to 2.1.5 and document the batch-import fixes and security
hardening from the recent review (PRs #27#29).

- open-data-wizard.php: version 2.1.4 -> 2.1.5 (header + ODW_VERSION)
- CHANGELOG.md: new 2.1.5 entry (batch-import repair, demo dataset, cache
  TTL, CLI cache clear, quality clamp, delta overflow, XSS/CSV-injection/
  JSON-LD @id hardening, upload validation, 2000-record cap)
- README.md: batch-import notes (integer byte_size, Excel/BOM support,
  2000-record limit, formula-injection neutralization), version badge
- SECURITY.md: 2.1.5 version-history row, test count 90 -> 92, audit date
- API.md: document that delta `since` rejects overflow/invalid dates
- CLAUDE.md: add ODW_Batch_Import to structure + class table, correct CLI
  method names, test count 90 -> 92, current version 2.1.5
- E2E_TESTING.md: version/date footer

Tests: 92 pass, PHPStan clean, PHPCS exit 0.


Claude-Session: https://claude.ai/code/session_01JB1xUQM892bVZ4Yv3MZjvq

Co-authored-by: Claude <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants