Skip to content

fix(security): comprehensive security audit remediations#12

Merged
DavidLambauer merged 18 commits intomainfrom
fix/security-audit-remediations
Apr 14, 2026
Merged

fix(security): comprehensive security audit remediations#12
DavidLambauer merged 18 commits intomainfrom
fix/security-audit-remediations

Conversation

@DavidLambauer
Copy link
Copy Markdown
Member

Summary

Comprehensive security audit and remediation of the TypeSense Magento 2 extension, addressing 11 vulnerabilities across 3 severity levels.

Critical Fixes

High Fixes

Medium Fixes

Test plan

  • Verify AI assistant chat works with sanitized history (no regression)
  • Verify SQL sandbox blocks: SELECT 1 UNION SELECT * FROM admin_user, SELECT * INTO OUTFILE..., SELECT SUBSTR(value,1,1) FROM core_config_data
  • Verify system prompt is NOT visible in browser Network tab response
  • Verify rate limiting kicks in after 100 requests
  • Verify CDN scripts load with SRI (check console for integrity errors)
  • Verify category merchandiser save still works (POST only)
  • Run full test suite in Warden environment

… from response

- Validate client-supplied history: only allow 'user' and 'assistant' roles
- Strip tool_calls, system messages, and tool results from client history
- Filter response messages to prevent leaking system prompt and tool internals

Fixes #1, Fixes #3
- Replace str_contains keyword blocking with word-boundary regex
- Block UNION, INTO, OUTFILE, DUMPFILE, LOAD_FILE, CALL, SET, PREPARE, EXECUTE
- Block SQL comments (/**/, --, #)
- Resolve table prefixes via ResourceConnection::getTableName()
- Expand blocked columns: token, secret, api_key, passphrase, private_key
- Expand blocked tables: integration, email_template, vault_payment_token
- Block string extraction functions (SUBSTR, HEX, etc) on core_config_data
- Sanitize SQL error messages: return generic errors, don't leak schema info
- Add comprehensive tests for all new bypass protections

Fixes #2, Fixes #5, Fixes #6, Fixes #10
- 100 requests per hour per admin user
- Uses Magento cache with TTL-based sliding window
- Logs rate limit violations with admin ID

Fixes #4
Add sha384 integrity hash and crossorigin="anonymous" to all Typesense
JS CDN script tags across results, autocomplete, category listing,
and recommendations templates.

Fixes #7
- Log all SQL queries before execution (info level)
- Log blocked queries with reason (warning level)
- Log execution errors with query context (error level)
- All logs truncated to 500 chars for safety

Fixes #8
Prevents resource exhaustion from expensive queries. Logs timeout
events with elapsed time and iteration count.

Fixes #9
…r Save

Save controller should only handle POST requests. GET functionality
is already provided by the Load controller. Removing dual interface
ensures proper CSRF protection for all Save requests.

Fixes #11
…tructor

- Replace nullsafe ?-> with explicit null check for _auth->getUser()
- Pass ResourceConnection mock to SqlSandbox in DescribeDatabaseToolTest
@DavidLambauer DavidLambauer force-pushed the fix/security-audit-remediations branch from e78fcc4 to 2e576d5 Compare April 14, 2026 08:16
CacheInterface::load() PHPDoc return type makes ?: operator
unreachable. Use explicit false check instead.
PHPStan fixes (3 errors):
- Use array condition for addFieldToFilter in CustomerDataBuilder and OrderDataBuilder
- Remove stale @param $entityIds PHPDoc in SystemConfigDataBuilder

Unit test error fixes (18 errors):
- CustomerDataBuilderTest: use getMockBuilder with addMethods for magic __call getters
- CustomerDataBuilderTest: return plain string from getRegion instead of RegionInterface mock
- OrderDataBuilderTest: use getMockBuilder with addMethods for methods not on OrderInterface

Unit test failure fixes (32 failures):
- Fix int vs float assertSame across 16 tool test files (JSON roundtrip makes whole floats into ints)
- Fix AdminConversationModelManagerTest max_bytes: 16384 -> 65536 to match implementation
- CustomerDataBuilderTest: move getId and getAddresses to onlyMethods (exist on Customer)
- OrderDataBuilderTest: move interface-declared methods to onlyMethods, keep magic methods in addMethods
@DavidLambauer DavidLambauer merged commit 11f5c2b into main Apr 14, 2026
10 of 11 checks passed
@DavidLambauer DavidLambauer deleted the fix/security-audit-remediations branch April 15, 2026 22:12
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.

1 participant