Changeset 3841327
- Timestamp:
- 12/02/2026 11:29:59 PM (less than one hour ago)
- Location:
- awp-support-desk/trunk
- Files:
-
- 1 added
- 16 edited
-
awp-support-desk.php (modified) (2 diffs)
-
includes/core/Database/Migrations/CreateCustomerTable.php (modified) (1 diff)
-
includes/core/Database/Migrations/RepairCustomerTimestamps.php (added)
-
includes/core/Database/Schema.php (modified) (2 diffs)
-
includes/core/Support/RateLimiter.php (modified) (1 diff)
-
includes/free/Admin/Notice.php (modified) (1 diff)
-
includes/free/Admin/TicketActions.php (modified) (6 diffs)
-
includes/free/Portal/PortalController.php (modified) (2 diffs)
-
includes/free/Rest/AttachmentsController.php (modified) (2 diffs)
-
includes/free/Rest/MessagesController.php (modified) (2 diffs)
-
includes/free/Rest/TicketsController.php (modified) (2 diffs)
-
includes/free/Tickets/AttachmentController.php (modified) (2 diffs)
-
readme.txt (modified) (3 diffs)
-
vendor/autoload.php (modified) (1 diff)
-
vendor/composer/autoload_classmap.php (modified) (1 diff)
-
vendor/composer/autoload_real.php (modified) (2 diffs)
-
vendor/composer/autoload_static.php (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
awp-support-desk/trunk/awp-support-desk.php
r3838880 r3841327 4 4 * Plugin URI: https://awp-software.com/support-desk 5 5 * Description: Self-hosted support ticket system for WordPress teams. Unlimited tickets and agents. 6 * Version: 1.2. 06 * Version: 1.2.1 7 7 * Requires at least: 6.6 8 8 * Requires PHP: 8.1 … … 27 27 } 28 28 29 define( 'AWP_SUPPORT_DESK_VERSION', '1.2. 0' );29 define( 'AWP_SUPPORT_DESK_VERSION', '1.2.1' ); 30 30 define( 'AWP_SUPPORT_DESK_FILE', __FILE__ ); 31 31 define( 'AWP_SUPPORT_DESK_DIR', plugin_dir_path( __FILE__ ) ); -
awp-support-desk/trunk/includes/core/Database/Migrations/CreateCustomerTable.php
r3820864 r3841327 41 41 name VARCHAR(191) NOT NULL, 42 42 locale VARCHAR(10) NOT NULL DEFAULT 'en_US', 43 created_at DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00',44 updated_at DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00',43 created_at DATETIME NOT NULL, 44 updated_at DATETIME NOT NULL, 45 45 PRIMARY KEY (id), 46 46 KEY site_email (site_id, email) -
awp-support-desk/trunk/includes/core/Database/Schema.php
r3814420 r3841327 17 17 use Awp\Core\Database\Migrations\CreateCustomerTable; 18 18 use Awp\Core\Database\Migrations\CreateTicketTables; 19 use Awp\Core\Database\Migrations\RepairCustomerTimestamps; 19 20 20 21 /** … … 35 36 */ 36 37 public static function migrations(): array { 37 $base = array( new CreateTicketTables(), new AddInboxIndexes(), new AddTicketCategories(), new CreateCustomerTable() ); 38 $base = array( 39 new CreateTicketTables(), 40 new AddInboxIndexes(), 41 new AddTicketCategories(), 42 new CreateCustomerTable(), 43 new RepairCustomerTimestamps(), 44 ); 38 45 39 46 /** -
awp-support-desk/trunk/includes/core/Support/RateLimiter.php
r3814420 r3841327 34 34 35 35 public const CACHE_GROUP = 'awp_rl'; 36 37 /** 38 * Headroom the shared address bucket gets over a single account. 39 * 40 * Coordinated accounts multiply a per-user ceiling, so each surface also 41 * counts hits per client address. The address ceiling is deliberately 42 * higher than the per-user one so an office behind one NAT address is not 43 * throttled while it stays within ten times a single account. 44 */ 45 private const ADDRESS_MULTIPLIER = 10; 46 47 /** Never give the address bucket less room than this. */ 48 private const ADDRESS_MIN_LIMIT = 30; 49 50 /** 51 * Check a user bucket and the shared address bucket. 52 * 53 * Both buckets use the same fixed window. The address only comes from 54 * `ClientIp::fromServer()`, which trusts `REMOTE_ADDR` alone, so a forged 55 * forwarded header cannot hand the caller a fresh ceiling. The address is 56 * hashed so the transient name stays short and carries no raw address. 57 * 58 * @param string $bucket Surface-specific prefix, unique per action. 59 * @param int $userId Current user id. 60 * @param int $limit Maximum hits per user inside the window. 61 * @param int $window Window length in seconds. 62 */ 63 public function guard( string $bucket, int $userId, int $limit, int $window ): bool { 64 if ( $this->hit( $bucket . '_user_' . $userId, $limit, $window ) ) { 65 return true; 66 } 67 68 // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- ClientIp validates the address with filter_var(). 69 $ip = ClientIp::fromServer( $_SERVER ); 70 71 if ( '' === $ip ) { 72 return false; 73 } 74 75 return $this->hit( 76 $bucket . '_addr_' . md5( $ip ), 77 max( self::ADDRESS_MIN_LIMIT, $limit * self::ADDRESS_MULTIPLIER ), 78 $window 79 ); 80 } 81 82 /** 83 * Resolve a ceiling, letting the site override it without a release. 84 * 85 * The audit asked for post-beta tuning; a filter keeps the calibration in 86 * the site instead of hard-coding a value that only fits one workload. 87 * 88 * @param string $name Bucket name, for example `portal_create`. 89 * @param int $fallback Ceiling applied when the site does not override it. 90 */ 91 public static function limit( string $name, int $fallback ): int { 92 /** 93 * Filters the rate-limit ceilings per bucket. 94 * 95 * @param array<string, int> $limits Bucket name => maximum hits per window. 96 */ 97 $limits = apply_filters( 'awp/rate_limits', array() ); 98 99 if ( ! is_array( $limits ) || ! isset( $limits[ $name ] ) || ! is_numeric( $limits[ $name ] ) ) { 100 return max( 1, $fallback ); 101 } 102 103 return max( 1, (int) $limits[ $name ] ); 104 } 36 105 37 106 /** -
awp-support-desk/trunk/includes/free/Admin/Notice.php
r3828148 r3841327 40 40 'attach_error' => array( __( 'The file could not be attached. Please try again.', 'awp-support-desk' ), 'error' ), 41 41 'attach_throttled' => array( __( 'Too many uploads. Please wait a few minutes and try again.', 'awp-support-desk' ), 'error' ), 42 'throttled' => array( __( 'Too many actions. Please wait a few minutes and try again.', 'awp-support-desk' ), 'error' ), 42 43 'invalid' => array( __( 'Please check the form and try again.', 'awp-support-desk' ), 'error' ), 43 44 'error' => array( __( 'Something went wrong. Please try again.', 'awp-support-desk' ), 'error' ), -
awp-support-desk/trunk/includes/free/Admin/TicketActions.php
r3828148 r3841327 15 15 use Awp\Core\Roles\Capabilities; 16 16 use Awp\Core\Support\ClientIp; 17 use Awp\Core\Support\RateLimiter; 17 18 use Awp\Core\Tickets\Actor; 18 19 use Awp\Core\Tickets\AttachmentService; … … 33 34 final class TicketActions { 34 35 36 /** 37 * Staff writes are authenticated and capability-checked, but an agent 38 * account is still an account: the audit asked for a ceiling on status, 39 * priority, category and assignment edits instead of leaving them 40 * unthrottled. One bucket covers single edits, replies and batches. 41 */ 42 private const STAFF_LIMIT = 60; 43 private const LIMIT_WINDOW = 600; 44 35 45 public function __construct( 36 46 private readonly TicketService $tickets, … … 52 62 if ( 0 >= $ticketId || ! current_user_can( Capabilities::VIEW_TICKETS, $ticketId ) ) { 53 63 $this->forbidden( __( 'You do not have permission to update this ticket.', 'awp-support-desk' ) ); 64 } 65 66 if ( $this->throttled() ) { 67 $this->redirectTicket( $ticketId, 'throttled' ); 54 68 } 55 69 … … 64 78 } 65 79 80 $this->redirectTicket( $ticketId, $notice ); 81 } 82 83 /** 84 * Send the agent back to the ticket with the result of the action. 85 */ 86 private function redirectTicket( int $ticketId, string $notice ): never { 66 87 wp_safe_redirect( 67 88 add_query_arg( … … 110 131 if ( 'assignee' === $kind && ! current_user_can( Capabilities::ASSIGN_TICKETS ) ) { 111 132 $this->forbidden( __( 'You do not have permission to assign tickets.', 'awp-support-desk' ) ); 133 } 134 135 if ( $this->throttled() ) { 136 $this->redirectBulk( 'throttled', 0 ); 112 137 } 113 138 … … 418 443 } 419 444 445 /** 446 * Per-user and per-address throttle for staff writes. 447 */ 448 private function throttled(): bool { 449 return ( new RateLimiter() )->guard( 450 'awp_admin_rl_staff', 451 get_current_user_id(), 452 RateLimiter::limit( 'admin_staff', self::STAFF_LIMIT ), 453 self::LIMIT_WINDOW 454 ); 455 } 456 420 457 private function postBody(): string { 421 458 // phpcs:ignore WordPress.Security.NonceVerification.Missing -- The nonce is verified by handle(). -
awp-support-desk/trunk/includes/free/Portal/PortalController.php
r3828148 r3841327 36 36 final class PortalController { 37 37 38 private const CREATE_LIMIT = 5;39 private const REPLY_LIMIT = 20;38 private const CREATE_LIMIT = 3; 39 private const REPLY_LIMIT = 15; 40 40 private const LIMIT_WINDOW = 600; 41 41 … … 197 197 198 198 /** 199 * Per-user throttle for portal writes.199 * Per-user and per-address throttle for portal writes. 200 200 */ 201 201 private function isThrottled( string $action, int $limit ): bool { 202 return ( new RateLimiter() )->hit( 203 'awp_portal_rl_' . $action . '_' . get_current_user_id(), 204 $limit, 202 return ( new RateLimiter() )->guard( 203 'awp_portal_rl_' . $action, 204 get_current_user_id(), 205 RateLimiter::limit( 'portal_' . $action, $limit ), 205 206 self::LIMIT_WINDOW 206 207 ); -
awp-support-desk/trunk/includes/free/Rest/AttachmentsController.php
r3814420 r3841327 40 40 final class AttachmentsController { 41 41 42 private const UPLOAD_LIMIT = 30;42 private const UPLOAD_LIMIT = 20; 43 43 private const LIMIT_WINDOW = 600; 44 44 … … 212 212 213 213 /** 214 * Per-user throttle for uploads.214 * Per-user and per-address throttle for uploads. 215 215 */ 216 216 private function throttled(): bool { 217 return ( new RateLimiter() )->hit( 218 'awp_rest_rl_upload_' . get_current_user_id(), 219 self::UPLOAD_LIMIT, 217 return ( new RateLimiter() )->guard( 218 'awp_rest_rl_upload', 219 get_current_user_id(), 220 RateLimiter::limit( 'rest_upload', self::UPLOAD_LIMIT ), 220 221 self::LIMIT_WINDOW 221 222 ); -
awp-support-desk/trunk/includes/free/Rest/MessagesController.php
r3814420 r3841327 40 40 final class MessagesController { 41 41 42 private const REPLY_LIMIT = 20;42 private const REPLY_LIMIT = 15; 43 43 private const LIMIT_WINDOW = 600; 44 44 … … 233 233 234 234 /** 235 * Per-user throttle for public replies and internal notes.235 * Per-user and per-address throttle for public replies and internal notes. 236 236 */ 237 237 private function throttled(): bool { 238 return ( new RateLimiter() )->hit( 239 'awp_rest_rl_reply_' . get_current_user_id(), 240 self::REPLY_LIMIT, 238 return ( new RateLimiter() )->guard( 239 'awp_rest_rl_reply', 240 get_current_user_id(), 241 RateLimiter::limit( 'rest_reply', self::REPLY_LIMIT ), 241 242 self::LIMIT_WINDOW 242 243 ); -
awp-support-desk/trunk/includes/free/Rest/TicketsController.php
r3814420 r3841327 43 43 final class TicketsController { 44 44 45 private const CREATE_LIMIT = 5;45 private const CREATE_LIMIT = 3; 46 46 private const LIMIT_WINDOW = 600; 47 47 … … 585 585 586 586 /** 587 * Per-user throttle for ticket creation.587 * Per-user and per-address throttle for ticket creation. 588 588 */ 589 589 private function throttled( string $action, int $limit ): bool { 590 return ( new RateLimiter() )->hit( 591 'awp_rest_rl_' . $action . '_' . get_current_user_id(), 592 $limit, 590 return ( new RateLimiter() )->guard( 591 'awp_rest_rl_' . $action, 592 get_current_user_id(), 593 RateLimiter::limit( 'rest_' . $action, $limit ), 593 594 self::LIMIT_WINDOW 594 595 ); -
awp-support-desk/trunk/includes/free/Tickets/AttachmentController.php
r3814420 r3841327 34 34 final class AttachmentController { 35 35 36 private const UPLOAD_LIMIT = 30;36 private const UPLOAD_LIMIT = 20; 37 37 private const UPLOAD_WINDOW = 600; 38 38 … … 177 177 178 178 private function throttled(): bool { 179 return ( new RateLimiter() )->hit( 180 'awp_attach_rl_' . get_current_user_id(), 181 self::UPLOAD_LIMIT, 179 return ( new RateLimiter() )->guard( 180 'awp_attach_rl', 181 get_current_user_id(), 182 RateLimiter::limit( 'admin_upload', self::UPLOAD_LIMIT ), 182 183 self::UPLOAD_WINDOW 183 184 ); -
awp-support-desk/trunk/readme.txt
r3838880 r3841327 5 5 Tested up to: 7.1 6 6 Requires PHP: 8.1 7 Stable tag: 1.2. 07 Stable tag: 1.2.1 8 8 License: GPLv2 or later 9 9 License URI: https://www.gnu.org/licenses/gpl-2.0.html … … 132 132 133 133 == Changelog == 134 135 = 1.2.1 = 136 * Fixed: the customer table no longer declares `0000-00-00 00:00:00` as the default of its timestamp 137 columns, a value MySQL 8 in strict mode rejects. Revision `0012` repairs installations that already 138 ran the old revision by rewriting zero-date rows and leaving both columns `DATETIME NOT NULL` 139 without a default. 140 * Fixed: the hidden file input on the ticket screen no longer widens the page, and the inbox 141 timestamp meets WCAG AA contrast. 142 * Changed: rate limits tuned after the security audit. Opening a ticket allows 3 hits per 10 minutes, 143 a reply 15 and an upload 20; each surface also checks a shared client-address bucket at ten times 144 the ceiling. Staff writes from the ticket screen share a 60-per-10-minute bucket instead of being 145 unthrottled, and every ceiling can be overridden through the `awp/rate_limits` filter. 134 146 135 147 = 1.2.0 = … … 277 289 == Upgrade Notice == 278 290 291 = 1.2.1 = 292 Database and rate-limit update. Revision 0012 runs automatically on upgrade; no action is required 293 and no content is removed. Existing tickets, customers, messages, attachments, roles and settings are 294 preserved. 295 279 296 = 1.2.0 = 280 297 Email and promotion update. No database schema change and no action required on upgrade; tickets, -
awp-support-desk/trunk/vendor/autoload.php
r3838880 r3841327 20 20 require_once __DIR__ . '/composer/autoload_real.php'; 21 21 22 return ComposerAutoloaderInit 3e5cdf49c67905810b34d4f820411b29::getLoader();22 return ComposerAutoloaderInit268bb495d1f55039631247c176f1b132::getLoader(); -
awp-support-desk/trunk/vendor/composer/autoload_classmap.php
r3838880 r3841327 22 22 'Awp\\Core\\Database\\Migrations\\CreateCustomerTable' => $baseDir . '/includes/core/Database/Migrations/CreateCustomerTable.php', 23 23 'Awp\\Core\\Database\\Migrations\\CreateTicketTables' => $baseDir . '/includes/core/Database/Migrations/CreateTicketTables.php', 24 'Awp\\Core\\Database\\Migrations\\RepairCustomerTimestamps' => $baseDir . '/includes/core/Database/Migrations/RepairCustomerTimestamps.php', 24 25 'Awp\\Core\\Database\\Migrator' => $baseDir . '/includes/core/Database/Migrator.php', 25 26 'Awp\\Core\\Database\\OptionVersionStore' => $baseDir . '/includes/core/Database/OptionVersionStore.php', -
awp-support-desk/trunk/vendor/composer/autoload_real.php
r3838880 r3841327 3 3 // autoload_real.php @generated by Composer 4 4 5 class ComposerAutoloaderInit 3e5cdf49c67905810b34d4f820411b295 class ComposerAutoloaderInit268bb495d1f55039631247c176f1b132 6 6 { 7 7 private static $loader; … … 23 23 } 24 24 25 spl_autoload_register(array('ComposerAutoloaderInit 3e5cdf49c67905810b34d4f820411b29', 'loadClassLoader'), true, true);25 spl_autoload_register(array('ComposerAutoloaderInit268bb495d1f55039631247c176f1b132', 'loadClassLoader'), true, true); 26 26 self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(__DIR__)); 27 spl_autoload_unregister(array('ComposerAutoloaderInit 3e5cdf49c67905810b34d4f820411b29', 'loadClassLoader'));27 spl_autoload_unregister(array('ComposerAutoloaderInit268bb495d1f55039631247c176f1b132', 'loadClassLoader')); 28 28 29 29 require __DIR__ . '/autoload_static.php'; 30 call_user_func(\Composer\Autoload\ComposerStaticInit 3e5cdf49c67905810b34d4f820411b29::getInitializer($loader));30 call_user_func(\Composer\Autoload\ComposerStaticInit268bb495d1f55039631247c176f1b132::getInitializer($loader)); 31 31 32 32 $loader->setClassMapAuthoritative(true); -
awp-support-desk/trunk/vendor/composer/autoload_static.php
r3838880 r3841327 5 5 namespace Composer\Autoload; 6 6 7 class ComposerStaticInit 3e5cdf49c67905810b34d4f820411b297 class ComposerStaticInit268bb495d1f55039631247c176f1b132 8 8 { 9 9 public static $prefixLengthsPsr4 = array ( … … 42 42 'Awp\\Core\\Database\\Migrations\\CreateCustomerTable' => __DIR__ . '/../..' . '/includes/core/Database/Migrations/CreateCustomerTable.php', 43 43 'Awp\\Core\\Database\\Migrations\\CreateTicketTables' => __DIR__ . '/../..' . '/includes/core/Database/Migrations/CreateTicketTables.php', 44 'Awp\\Core\\Database\\Migrations\\RepairCustomerTimestamps' => __DIR__ . '/../..' . '/includes/core/Database/Migrations/RepairCustomerTimestamps.php', 44 45 'Awp\\Core\\Database\\Migrator' => __DIR__ . '/../..' . '/includes/core/Database/Migrator.php', 45 46 'Awp\\Core\\Database\\OptionVersionStore' => __DIR__ . '/../..' . '/includes/core/Database/OptionVersionStore.php', … … 168 169 { 169 170 return \Closure::bind(function () use ($loader) { 170 $loader->prefixLengthsPsr4 = ComposerStaticInit 3e5cdf49c67905810b34d4f820411b29::$prefixLengthsPsr4;171 $loader->prefixDirsPsr4 = ComposerStaticInit 3e5cdf49c67905810b34d4f820411b29::$prefixDirsPsr4;172 $loader->classMap = ComposerStaticInit 3e5cdf49c67905810b34d4f820411b29::$classMap;171 $loader->prefixLengthsPsr4 = ComposerStaticInit268bb495d1f55039631247c176f1b132::$prefixLengthsPsr4; 172 $loader->prefixDirsPsr4 = ComposerStaticInit268bb495d1f55039631247c176f1b132::$prefixDirsPsr4; 173 $loader->classMap = ComposerStaticInit268bb495d1f55039631247c176f1b132::$classMap; 173 174 174 175 }, null, ClassLoader::class);
Note:
See TracChangeset
for help on using the changeset viewer.