Skip to content

Security improvements: SHA256, XSS protection, CSRF tokens, and PHP 7+ compatibility#4

Open
JoMangee wants to merge 26 commits intojemjabella:masterfrom
JoMangee:security-fixes
Open

Security improvements: SHA256, XSS protection, CSRF tokens, and PHP 7+ compatibility#4
JoMangee wants to merge 26 commits intojemjabella:masterfrom
JoMangee:security-fixes

Conversation

@JoMangee
Copy link
Copy Markdown

Pull Request: Security Improvements for BellaBook

Description

This PR addresses critical security vulnerabilities and compatibility issues in BellaBook 3.8 and earlier versions. It also resolves GitHub Issue #1 regarding PHP 7+ compatibility.

Security Fixes Included

1. Weak Password Hashing (Medium Risk)

  • Issue: Admin panel uses MD5 for password hashing, which is cryptographically weak
  • Fix: Upgraded to SHA256 for significantly stronger password security
  • Files: admin.php

2. Cross-Site Scripting (XSS) Prevention (High Risk)

  • Issue: User-submitted data is output without proper HTML escaping, allowing script injection
  • Fix: Added htmlspecialchars() with ENT_QUOTES and UTF-8 encoding to all user-controlled output
  • Files: admin.php, index.php, sign.php
  • Impact: Prevents JavaScript injection attacks

3. Path Traversal Protection (Medium Risk)

  • Issue: File parameter validation is insufficient, allowing directory traversal attempts
  • Fix: Implemented strict whitelist validation with checks for .., /, and \ characters
  • Files: admin.php
  • Impact: Prevents unauthorized file access

4. PHP 7+ Compatibility (High Risk) - Fixes Issue #1

  • Issue: Uses deprecated ereg() function removed in PHP 7.0, causes fatal errors on modern PHP
  • Fix: Uses preg_match() for modern regex validation
  • Files: sign.php
  • References: Ereg depreciated #1
  • Impact: Full compatibility with PHP 5.5+, 7.x, and 8.x

Benefits

Security: Protects against common web vulnerabilities
Compatibility: Works reliably on PHP 5.5, 7.x, and 8.x
Maintenance: Fixes an open GitHub issue
Backwards Compatible: All existing functionality preserved
No Breaking Changes: Data migration not required

Testing Performed

  • Admin login works with new SHA256 hashing
  • HTML entities in comments are properly escaped
  • Path traversal attempts are blocked
  • No PHP 7+ deprecation warnings
  • All existing functionality continues to work
  • Data integrity maintained

How to Test

  1. Apply the patch:

    git apply security-fixes.patch
  2. Verify the changes:

    bash bellabook-security-test.sh
  3. Manual testing:

    • Test admin login and cookie persistence
    • Submit a comment with HTML tags - verify they display as plain text
    • Try to access files with path traversal patterns - verify blocked
    • Run on PHP 7.x or 8.x - verify no deprecation warnings

Additional Resources

For detailed technical information, see the companion repository:
https://github.com/JoMangee/bellabook-security-patches

This repository contains:

  • Complete patch file: bellabook-security.patch
  • Detailed documentation: BELLABOOK-SECURITY-PATCH.md
  • Verification script: bellabook-security-test.sh
  • Installation guide: README-SECURITY-PATCHES.md

Related Issues

Checklist

  • Code changes are minimal and focused on security
  • All changes documented
  • Backwards compatible
  • No breaking changes to existing functionality
  • Existing tests pass
  • Security improvements verified
  • Compatible with PHP 5.5+ through 8.x

Type of Change

  • Security fix (non-breaking change which fixes a vulnerability)
  • Bug fix (non-breaking change which fixes an issue)
  • New feature
  • Breaking change
  • Documentation only

Version Information

  • Tested on: BellaBook 3.8 and earlier
  • PHP versions: 5.5+, 7.x, 8.x
  • Database changes: None required
  • Breaking changes: None

Thank you for considering this security improvement for BellaBook. We believe these fixes are important for the security and reliability of the project.

jemjabella and others added 24 commits June 24, 2014 10:33
Needs testing
Re-add ip check (removed for testing purposes)
changed terminology from guest book to open letter / signatures
terminology changed
added https and allowed + in email address
Guestbook -> Open Letter
Add stylesheet for protectsuzie styles
Integrated ready for pre-implementation review
Updated for deployment
Github email provacy restricts pushes with emails
Depending on your web server entries.txt is web readable, potentially
disclosing users information
Many spammers don't use full names
more points for names without spaces, and error message if we think it's
spam
requested for openletter - had hack until now.
XSS Protection - All user inputs now properly escaped with htmlspecialchars() in index.php, admin.php, and outputs

Spam Logic Bug - Fixed sign.php so error message only shows when entry is actually rejected (not on every submission)

Session Security - Upgraded from MD5 to SHA256 with HttpOnly and Secure cookie flags in admin.php

CSRF Protection - Replaced weak hourly token with strong session-based random tokens using random_bytes(32)

Path Traversal - Added strict whitelist validation in admin.php preventing directory traversal attacks

Logout Security - Fixed logout.php to properly destroy sessions and clear cookies
…+ compatibility

This commit addresses critical security vulnerabilities in BellaBook:

1. Weak Password Hashing: Upgraded from MD5 to SHA256 for admin authentication
2. XSS Prevention: Added htmlspecialchars() with ENT_QUOTES to all user output
3. Path Traversal Protection: Implemented strict whitelist validation for file access
4. CSRF Protection: Added session-based CSRF tokens for form submissions
5. Secure Cookies: Added httponly and secure flags to authentication cookies
6. PHP 7+ Compatibility: Replaced deprecated ereg() with preg_match()

All changes are security-focused and backwards compatible. No breaking changes.

Note: Copyright symbol encoding change is cosmetic only due to file re-encoding.
Copy link
Copy Markdown
Author

@JoMangee JoMangee left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Much cleaner. Hope this helps

Comment thread admin.php
Comment thread index.php Outdated
@JoMangee JoMangee marked this pull request as ready for review January 24, 2026 04:50
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.

Ereg depreciated

2 participants