T.ME/BIBIL_0DAY
CasperSecurity


Server : Apache/2
System : Linux server-15-235-50-60 5.15.0-164-generic #174-Ubuntu SMP Fri Nov 14 20:25:16 UTC 2025 x86_64
User : gositeme ( 1004)
PHP Version : 8.2.29
Disable Function : exec,system,passthru,shell_exec,proc_close,proc_open,dl,popen,show_source,posix_kill,posix_mkfifo,posix_getpwuid,posix_setpgid,posix_setsid,posix_setuid,posix_setgid,posix_seteuid,posix_setegid,posix_uname
Directory :  /home/gositeme/domains/soundstudiopro.com/private_html/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : /home/gositeme/domains/soundstudiopro.com/private_html/AUDIO_PLAYBACK_AUDIT.md
# ๐Ÿ” AUDIO PLAYBACK AUDIT - Token & .htaccess Issues

**Date:** December 2025  
**Status:** COMPREHENSIVE AUDIT COMPLETE

---

## ๐Ÿ“‹ EXECUTIVE SUMMARY

After the security breach, `.htaccess` files were modified site-wide. This audit identifies potential issues preventing audio playback through `utils/play_audio.php` and the global player.

---

## ๐Ÿ”ด CRITICAL ISSUES IDENTIFIED

### Issue 1: Main .htaccess Rewrite Rules May Interfere

**Location:** `/.htaccess`

**Current Rules:**
```apache
# Don't rewrite existing files or directories
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

# Rewrite everything else to index.php
RewriteRule . /index.php [L]
```

**Problem:**
- The main `.htaccess` doesn't explicitly allow `/utils/` directory
- While it should work (checks for existing files first), there may be edge cases
- The rewrite rules apply BEFORE directory-specific `.htaccess` files

**Recommendation:**
Add explicit exception for `/utils/play_audio.php` to ensure it's never rewritten.

---

### Issue 2: Token Validation Parameter Mismatch

**Location:** `utils/play_audio.php`

**Current Code Flow:**
1. Lines 261-265: Gets parameters from URL
2. Lines 267-332: Referrer validation (allows Range requests)
3. Lines 354-356: Gets `$user_id` and `$session_id` from session
4. Lines 370-429: Token validation with proper parameters

**Status:** โœ… **CORRECT** - The main execution flow properly gets user_id and session_id before validation.

**However:** The function `validateAudioToken()` signature requires:
```php
validateAudioToken($trackId, $variationIndex, $token, $expires, $userId, $sessionId)
```

All calls in the main flow (lines 381, 394, 419, etc.) correctly pass these parameters.

---

### Issue 3: utils/.htaccess Configuration

**Location:** `utils/.htaccess`

**Current Configuration:**
```apache
# Allow play_audio.php - CRITICAL for music playback
<FilesMatch "^(play_audio\.php|audio_token\.php|index\.php)$">
 Order allow,deny
 Allow from all
</FilesMatch>

# Block other PHP files in utils directory (security)
<FilesMatch "\.php$">
 Order allow,deny
 Deny from all
</FilesMatch>
```

**Status:** โœ… **CORRECT** - This configuration:
- Allows `play_audio.php` โœ…
- Allows `audio_token.php` โœ… (required by play_audio.php)
- Blocks other PHP files โœ…

**Note:** The order matters - the allow rule must come BEFORE the deny rule.

---

### Issue 4: Session Handling in Token Validation

**Location:** `utils/audio_token.php` and `utils/play_audio.php`

**Potential Issue:**
- Tokens are bound to `user_id|session_id`
- If session changes (e.g., session regeneration), tokens become invalid
- Range requests (playback) may use different session state

**Current Handling:**
- Lines 394-403 in `play_audio.php` try multiple validation strategies:
  1. Current user + current session
  2. Guest + current session
  3. Current user + null session (backward compat)
  4. Guest + null session (legacy)

**Status:** โœ… **HANDLED** - Multiple fallback strategies should handle most cases.

---

## ๐ŸŸก POTENTIAL ISSUES

### Issue 5: Referrer Validation May Block Legitimate Requests

**Location:** `utils/play_audio.php` lines 267-332

**Current Logic:**
- Blocks direct URL access (page loads without referrer)
- Allows Range requests (playback/seeking)
- Allows if token is provided (line 329)

**Potential Problem:**
- If browser doesn't send referrer header, legitimate requests may be blocked
- Some browsers/extensions strip referrer headers for privacy

**Current Workaround:**
- Line 329: Allows if token is provided (token validation handles security)
- Range requests always allowed (line 270)

**Status:** โš ๏ธ **PARTIALLY MITIGATED** - Should work, but may need monitoring.

---

### Issue 6: Token Usage Tracking May Block Playback

**Location:** `utils/play_audio.php` lines 431-453

**Current Logic:**
- Marks token as "used" on page loads (not Range requests)
- Blocks if token already used AND it's a page load

**Potential Problem:**
- If token is marked as used on initial load, subsequent Range requests should work
- But if session changes, token usage tracking may be lost

**Status:** โœ… **SHOULD WORK** - Range requests don't consume uses.

---

## โœ… VERIFIED WORKING COMPONENTS

### 1. Token Generation (`api/get_audio_token.php`)
- โœ… Generates tokens with user_id and session_id
- โœ… Supports dynamic expiration based on track duration
- โœ… Returns signed URL with token and expires parameters

### 2. Global Player (`global_player.php`)
- โœ… Fetches fresh tokens before playback
- โœ… Uses `/api/get_audio_token.php` endpoint
- โœ… Passes track duration for proper token expiry
- โœ… Falls back to original URL if token fetch fails

### 3. Audio Token System (`utils/audio_token.php`)
- โœ… HMAC-SHA256 signature generation
- โœ… User/session binding prevents token sharing
- โœ… Multiple validation strategies for compatibility
- โœ… Usage tracking in session

---

## ๐Ÿ”ง RECOMMENDED FIXES

### Fix 1: Add Explicit Exception in Main .htaccess

**File:** `/.htaccess`

**Add before line 24:**
```apache
# Allow utils/play_audio.php - CRITICAL for audio playback
RewriteCond %{REQUEST_URI} ^/utils/play_audio\.php
RewriteRule ^ - [L]
```

**Why:** Ensures `/utils/play_audio.php` is never rewritten, even if there are edge cases with file detection.

---

### Fix 2: Improve Error Logging

**File:** `utils/play_audio.php`

**Add after line 332:**
```php
// Log access attempts for debugging
if (empty($token)) {
    error_log("AUDIO: Access attempt without token - track_id: $trackId, referrer: " . ($referrer ?: 'none'), range: " . ($isRangeRequest ? 'yes' : 'no'));
}
```

**Why:** Better debugging when playback fails.

---

### Fix 3: Add Global Player to Allowed Pages

**File:** `utils/play_audio.php`

**Update line 274-282:**
```php
$allowedPages = [
    'track.php',
    'community_fixed.php',
    'create_music.php',
    'radio/',
    'library',
    'admin_batch_analyze_tracks.php',
    'admin.php',
    'global_player.php', // Add this
    'index.php', // Add this (homepage may trigger player)
];
```

**Why:** Global player may be loaded from various pages.

---

## ๐Ÿงช TESTING CHECKLIST

### Test 1: Direct Access Test
- [ ] Try accessing `/utils/play_audio.php?id=123&token=abc&expires=1234567890` directly
- [ ] Should return 403 (expected - security feature)
- [ ] Should show access denied page

### Test 2: Token Generation Test
- [ ] Open browser console
- [ ] Run: `fetch('/api/get_audio_token.php?track_id=123')`
- [ ] Should return JSON with `success: true` and `url` field
- [ ] URL should contain token and expires parameters

### Test 3: Global Player Test
- [ ] Open a page with tracks (e.g., `community_fixed.php`)
- [ ] Click play on a track
- [ ] Check browser console for `๐ŸŽต` messages
- [ ] Check Network tab for `/utils/play_audio.php` request
- [ ] Response should be 200 (not 403/404)
- [ ] Response should be audio data (not error message)

### Test 4: Range Request Test
- [ ] Start playing a track
- [ ] Seek to middle of track
- [ ] Check Network tab for Range request
- [ ] Should return 206 (Partial Content)
- [ ] Audio should continue playing

### Test 5: Session Persistence Test
- [ ] Play a track
- [ ] Wait 30 seconds
- [ ] Seek to different position
- [ ] Should work (Range requests don't consume token uses)

---

## ๐Ÿ“Š DIAGNOSTIC COMMANDS

### Check .htaccess Rules
```bash
# Check main .htaccess
cat .htaccess | grep -A 5 "utils"

# Check utils/.htaccess
cat utils/.htaccess

# Test if play_audio.php is accessible
curl -I "https://soundstudiopro.com/utils/play_audio.php?id=123&token=test&expires=1234567890"
```

### Check PHP Errors
```bash
# Check error logs for audio-related errors
tail -f /path/to/error.log | grep -i "audio\|play_audio\|token"
```

### Check Session Issues
```php
// Add to play_audio.php temporarily for debugging
error_log("AUDIO DEBUG: user_id=" . ($user_id ?? 'null') . ", session_id=" . $session_id . ", token=" . substr($token, 0, 8));
```

---

## ๐ŸŽฏ ROOT CAUSE ANALYSIS

### Most Likely Causes:

1. **Main .htaccess Rewrite Interference** (30% probability)
   - Rewrite rules may interfere with `/utils/play_audio.php` requests
   - Fix: Add explicit exception

2. **Session Mismatch** (25% probability)
   - Tokens generated with one session, validated with another
   - Fix: Already handled with multiple validation strategies

3. **Referrer Header Missing** (20% probability)
   - Browser doesn't send referrer, request blocked
   - Fix: Already handled (allows if token provided)

4. **Token Expiration** (15% probability)
   - Tokens expire too quickly (5 minutes default)
   - Fix: Already handled (dynamic expiration based on duration)

5. **Token Usage Tracking** (10% probability)
   - Token marked as used, blocking subsequent requests
   - Fix: Already handled (Range requests don't consume uses)

---

## ๐Ÿ“ NEXT STEPS

1. **Apply Fix 1** - Add explicit exception in main `.htaccess`
2. **Apply Fix 2** - Improve error logging
3. **Apply Fix 3** - Add global player to allowed pages
4. **Test** - Run all tests in checklist
5. **Monitor** - Check error logs for audio-related issues
6. **Verify** - Confirm playback works in production

---

## ๐Ÿ”’ SECURITY NOTES

All fixes maintain security:
- โœ… Token validation still required
- โœ… User/session binding still enforced
- โœ… Direct URL access still blocked (without token)
- โœ… Private tracks still protected
- โœ… Token usage tracking still active

---

**Status:** Ready for fixes to be applied.


CasperSecurity Mini