Files
tomsjavajive/api/submit-review.php
myron 186ac0cb6d security: fix unauthenticated file upload/RCE risk, TLS bypass, XSS, and broken gift-card/review columns
- admin/api/upload-splash.php had NO admin-auth check (included the public
  customer header, not admin/includes/header.php) and both upload endpoints
  trusted the client-supplied MIME type and filename extension, so an
  attacker could name a file "shell.php", spoof Content-Type: image/png,
  and get PHP written into a web-reachable uploads/ directory. Added
  AdminAuth check and centralized real-content validation (getimagesize +
  server-side extension mapping) in a new handleImageUpload() helper used
  by both admin/upload-image.php and admin/api/upload-splash.php.
- Removed CURLOPT_SSL_VERIFYPEER => false from the CyberMail email calls
  in includes/email.php and includes/functions.php (MITM risk on the API
  key). Rewrote functions.php's sendEmail() as a thin wrapper around
  Email::send() so there's one implementation instead of two that could
  drift (this is what had the second copy of the TLS bypass).
- Escaped customer-controlled fields (customer_name, tracking info, reset
  URL) before interpolating into outbound HTML emails — name is free text
  from registration/checkout with no length/char restriction, so it was
  stored-HTML-injectable into every transactional email.
- Fixed api/redeem-gift-card.php referencing a nonexistent `balance` column
  on gift_cards (actual column is current_balance) — gift card redemption
  was completely broken, always returning "no remaining balance".
- Fixed api/submit-review.php inserting into nonexistent `content`/`status`
  columns on reviews (actual columns are `comment`/`is_approved`) — review
  submission was crashing on every request.
- Hardened .htaccess: block /db/*, /.git/*, and *.sql. Live site currently
  serves db/schema.sql and the full .git directory (including .git/config,
  which contains a GitHub PAT with push access) over HTTP — the existing
  config/includes RedirectMatch rules are also not being enforced live,
  see report for details; this needs a server-level fix too.
- Cleaned up README's leftover install instructions pointing at a deleted
  create-admin.php with a documented default password.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-07-04 14:22:50 -05:00

67 lines
1.9 KiB
PHP

<?php
/**
* Tom's Java Jive - Submit Review API
*/
header('Content-Type: application/json');
require_once __DIR__ . '/../includes/functions.php';
require_once __DIR__ . '/../includes/auth.php';
if ($_SERVER['REQUEST_METHOD'] !== 'POST') {
jsonResponse(['error' => 'Method not allowed'], 405);
}
if (!CustomerAuth::isLoggedIn()) {
jsonResponse(['error' => 'Please log in to submit a review'], 401);
}
$customer = CustomerAuth::getFullUser();
$input = json_decode(file_get_contents('php://input'), true);
$productId = $input['product_id'] ?? '';
$rating = intval($input['rating'] ?? 0);
$title = trim($input['title'] ?? '');
$content = trim($input['content'] ?? '');
if (empty($productId) || $rating < 1 || $rating > 5 || empty($content)) {
jsonResponse(['error' => 'Invalid input. Rating and review content are required.'], 400);
}
// Check if product exists
$product = db()->fetch("SELECT product_id FROM products WHERE product_id = :id", ['id' => $productId]);
if (!$product) {
jsonResponse(['error' => 'Product not found'], 404);
}
// Check if already reviewed
$existingReview = db()->fetch(
"SELECT review_id FROM reviews WHERE customer_id = :cid AND product_id = :pid",
['cid' => $customer['customer_id'], 'pid' => $productId]
);
if ($existingReview) {
jsonResponse(['error' => 'You have already reviewed this product'], 400);
}
// Create review
$reviewId = generateId('rev_');
db()->insert('reviews', [
'review_id' => $reviewId,
'product_id' => $productId,
'customer_id' => $customer['customer_id'],
'customer_name' => $customer['name'] ?? explode('@', $customer['email'])[0],
'customer_email' => $customer['email'],
'rating' => $rating,
'title' => $title,
'comment' => $content,
'is_approved' => 0 // Reviews require admin approval
]);
jsonResponse([
'success' => true,
'message' => 'Review submitted successfully. It will be visible after approval.',
'review_id' => $reviewId
]);