Skip to content

[5.x]: Axios call to /actions/matrix/create-entry failing with 400 #14618

@jonnykates

Description

@jonnykates

What happened?

Description

Attempting to add a Matrix 'block' to an entry is resulting in an Axios call to /actions/matrix/create-entry failing with a 400 error, with the message 'Invalid Matrix field ID: x'. This is only causing an issue when I deploy the site to a hosting plan with shared host Krystal.uk - I'm unable to recreate locally with DDEV. This would obviously suggest that there is some kind of dependency or security shortcoming on the Krystal server, but the payload to the endpoint also potentially suggests that the Matrix field ID is perhaps being sent as a string rather than an int (see Craft web log output below).

Steps to reproduce

To speed run seeing the error first hand, you can;

  1. Login to https://craft5matrixbug.jonnykates.com/admin/ with username admin and password password123.
  2. Go to create a new entry in the section 'My first section'
  3. Attempt to add a block/entry to the field 'A matrix 'field''
  4. The Craft draft will be 'dirty' but the block hasn't instantiated on the page
  5. The browser console will show you that an ajax call failed

You can clone the Craft config deployed above here. As I say, I can't recreate it locally; but I'm stumped. Obviously you can see the Craft system report page here and I can put that environment into allow admin changes if needed.

Expected behavior

An empty instance of the matrix block/field should be populated into the editor.

Actual behavior

The block doesn't appear.

Craft web log

2024-03-18 10:52:36 [web.INFO] [application] Request context:
$_GET = [
    'p' => 'admin/actions/matrix/create-entry'
    'v' => '1710784358227'
]

$_FILES = []

$_COOKIE = [
    '52374585177501565b605938acf58a53_username' => '8621a89a146acb6c38c9fec50869451f9f9a72259f9a7220e4fd0e9b0d2c57cea:2:{i:0;s:41:\"52374585177501565b605938acf58a53_username\";i:1;s:5:\"admin\";}'
    'Craft-5d075037-bb75-4d88-a5e3-a84e6274060b:sidebar' => 'expanded'
    'wschkid' => '6797899a72c25c78bcc06ed814a4360216c8fb63.1710869452.1'
    'CraftSessionId' => '797qk4l7br15u58bq0saa62cup'
    '52374585177501565b605938acf58a53_identity' => 'e0a53397f652fa6a09ee0df8b26ac8672627cf19996bccece3041bd0ee29110fa:2:{i:0;s:41:\"52374585177501565b605938acf58a53_identity\";i:1;s:159:\"[1,\"[\\\"T0jsM7uCBHzR-XEl7ToJvGXBZZxnIt4ZCM4YN_SZDSI_X9BAPzT4riu2td1P33n7zvCfHeBjVr38EcRrlvne4CsuLGxXZd-MV36p\\\",null,\\\"dd78878bebc0e6afff80be96516511d7\\\"]\",3600]\";}'
    'CRAFT_CSRF_TOKEN' => '••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••'
]

$_SESSION = [
    'e9e4afc1d10fa5eba531d8c56742ebde__flash' => []
    'e9e4afc1d10fa5eba531d8c56742ebde__auth_access' => [
        0 => 'previewDraft:1'
        1 => 'previewDraft:2'
    ]
    '52374585177501565b605938acf58a53__token' => '••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••'
    '52374585177501565b605938acf58a53__id' => 1
    '__authKey' => '••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••'
    '52374585177501565b605938acf58a53__expire' => 1710787956
    '__duration' => 3600
    '__elevated_timeout' => 1710783359
]

$_SERVER = [
    'PATH' => '/usr/local/bin:/bin:/usr/bin'
    'HTTP_ACCEPT' => 'application/json, text/plain, */*'
    'HTTP_ACCEPT_ENCODING' => 'gzip, deflate, br, zstd'
    'HTTP_ACCEPT_LANGUAGE' => 'en-GB,en;q=0.9'
    'CONTENT_TYPE' => 'application/json'
    'CONTENT_LENGTH' => '119'
    'HTTP_COOKIE' => '52374585177501565b605938acf58a53_username=8621a89a146acb6c38c9fec50869451f9f9a72259f9a7220e4fd0e9b0d2c57cea%3A2%3A%7Bi%3A0%3Bs%3A41%3A%2252374585177501565b605938acf58a53_username%22%3Bi%3A1%3Bs%3A5%3A%22admin%22%3B%7D; Craft-5d075037-bb75-4d88-a5e3-a84e6274060b:sidebar=expanded; wschkid=6797899a72c25c78bcc06ed814a4360216c8fb63.1710869452.1; CraftSessionId=797qk4l7br15u58bq0saa62cup; 52374585177501565b605938acf58a53_identity=e0a53397f652fa6a09ee0df8b26ac8672627cf19996bccece3041bd0ee29110fa%3A2%3A%7Bi%3A0%3Bs%3A41%3A%2252374585177501565b605938acf58a53_identity%22%3Bi%3A1%3Bs%3A159%3A%22%5B1%2C%22%5B%5C%22T0jsM7uCBHzR-XEl7ToJvGXBZZxnIt4ZCM4YN_SZDSI_X9BAPzT4riu2td1P33n7zvCfHeBjVr38EcRrlvne4CsuLGxXZd-MV36p%5C%22%2Cnull%2C%5C%22dd78878bebc0e6afff80be96516511d7%5C%22%5D%22%2C3600%5D%22%3B%7D; CRAFT_CSRF_TOKEN=1feb04fb6002711ac830acf9038518dfaf5748039bc1cbbf755da32d430dd120a%3A2%3A%7Bi%3A0%3Bs%3A16%3A%22CRAFT_CSRF_TOKEN%22%3Bi%3A1%3Bs%3A147%3A%22LC9hYV1IF6mWs1cLc4KWHorzAeFWimjNf-wRAbCD%7C531f061cc18b920fc9d5dc32b6f8f8eb8cacaa1b8c8fd5ee252b684b442c015eLC9hYV1IF6mWs1cLc4KWHorzAeFWimjNf-wRAbCD%7C1%22%3B%7D'
    'HTTP_HOST' => 'craft5matrixbug.jonnykates.com'
    'HTTP_PRAGMA' => 'no-cache'
    'HTTP_REFERER' => 'https://craft5matrixbug.jonnykates.com/admin/entries/myFirstSection/3?draftId=2'
    'HTTP_USER_AGENT' => 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Safari/537.36'
    'HTTP_CACHE_CONTROL' => 'no-cache'
    'HTTP_SEC_CH_UA' => '\"Chromium\";v=\"122\", \"Not(A:Brand\";v=\"24\", \"Google Chrome\";v=\"122\"'
    'HTTP_DNT' => '1'
    'HTTP_X_CSRF_TOKEN' => '••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••'
    'HTTP_SEC_CH_UA_MOBILE' => '?0'
    'HTTP_X_REGISTERED_ASSET_BUNDLES' => '92d8701,22e517a2,aee7f8dc,e505ffd6,6b4d7555,e5e48399,bb2f10a0,815d39ea,fc0bc163,1ccab40d,1e21896b,54698ee0,b842675b,1c3c9add,4b1fd285,d8d08e47,8f00ce04,8768f48b,cf3018d6,15a36a51'
    'HTTP_X_REGISTERED_JS_FILES' => ''
    'HTTP_X_REQUESTED_WITH' => 'XMLHttpRequest'
    'HTTP_SEC_CH_UA_PLATFORM' => '\"macOS\"'
    'HTTP_ORIGIN' => 'https://craft5matrixbug.jonnykates.com'
    'HTTP_SEC_FETCH_SITE' => 'same-origin'
    'HTTP_SEC_FETCH_MODE' => 'cors'
    'HTTP_SEC_FETCH_DEST' => 'empty'
    'HTTP_X_HTTPS' => '1'
    'DOCUMENT_ROOT' => '/home/cabcbesi/craft-5-matrix-bug/web'
    'REMOTE_ADDR' => '185.61.158.95'
    'REMOTE_PORT' => '60504'
    'SERVER_ADDR' => '77.72.2.85'
    'SERVER_NAME' => 'craft5matrixbug.jonnykates.com'
    'SERVER_ADMIN' => 'webmaster@craft5matrixbug.jonnykates.com.199ca18b81324176615c01507b1684e8-14451.sites.k-hosting.co.uk'
    'SERVER_PORT' => '443'
    'REQUEST_SCHEME' => 'https'
    'REQUEST_URI' => '/index.php?p=admin%2Factions%2Fmatrix%2Fcreate-entry&v=1710784358227'
    'HTTPS' => 'on'
    'WP_UPDATE_PHP_URL' => 'https://help.krystal.uk/cpanel/changing-your-php-version-extensions-functions-options'
    'CRAWLER_USLEEP' => '1000'
    'CRAWLER_LOAD_LIMIT' => '20'
    'X_SPDY' => 'HTTP3'
    'SSL_PROTOCOL' => 'QUIC'
    'SSL_CIPHER' => 'TLS_AES_128_GCM_SHA256'
    'SSL_CIPHER_USEKEYSIZE' => '128'
    'SSL_CIPHER_ALGKEYSIZE' => '128'
    'SCRIPT_FILENAME' => '/home/cabcbesi/craft-5-matrix-bug/web/index.php'
    'QUERY_STRING' => 'p=admin%2Factions%2Fmatrix%2Fcreate-entry&v=1710784358227'
    'SCRIPT_URI' => 'https://craft5matrixbug.jonnykates.com/index.php'
    'SCRIPT_URL' => '/index.php'
    'SCRIPT_NAME' => '/index.php'
    'SERVER_PROTOCOL' => 'HTTP/1.1'
    'SERVER_SOFTWARE' => 'LiteSpeed'
    'REQUEST_METHOD' => 'POST'
    'X-LSCACHE' => 'on,crawler'
    'PHP_SELF' => '/index.php'
    'REQUEST_TIME_FLOAT' => 1710784356.7187
    'REQUEST_TIME' => 1710784356
    'CRAFT_APP_ID' => 'CraftCMS--2584dd08-94b3-41fe-8b78-2beebc9a82ec'
    'CRAFT_ENVIRONMENT' => 'staging'
    'CRAFT_DB_DRIVER' => 'mysql'
    'CRAFT_DB_SERVER' => '127.0.0.1'
    'CRAFT_DB_PORT' => '3306'
    'CRAFT_DB_DATABASE' => 'cabcbesi_craft-5-matrix-bug'
    'CRAFT_DB_USER' => 'cabcbesi_craft-5-matrix-bug-user'
    'CRAFT_DB_PASSWORD' => '••••••••••••'
    'CRAFT_DB_SCHEMA' => 'public'
    'CRAFT_DB_TABLE_PREFIX' => ''
    'CRAFT_SECURITY_KEY' => '••••••••••••••••••••••••••••••••'
    'CRAFT_DEV_MODE' => 'true'
    'CRAFT_ALLOW_ADMIN_CHANGES' => 'false'
    'CRAFT_DISALLOW_ROBOTS' => 'true'
    'PRIMARY_SITE_URL' => 'https://craft5matrixbug.jonnykates.com'
] {"environment":"staging","userId":1,"sessionId":"797qk4l7br15u58bq0saa62cup","body":"{\"fieldId\":\"1\",\"entryTypeId\":1,\"ownerId\":3,\"ownerElementType\":\"craft\\\\elements\\\\Entry\",\"siteId\":1,\"namespace\":\"fields\"}"}

Craft CMS version

Craft Solo 5.0.0-beta.9

PHP version

8.2.16

Operating system and version

Linux 4.18.0-477.21.1.lve.1.el8.x86_64

Database type and version

MariaDB 10.6.17

Image driver and version

Imagick 3.7.0 (ImageMagick 7.1.1-19)

Installed plugins and versions

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions