8000 [symfony/mailjet-mailer] JSON payload for X-MJ-Vars only allows for a max depth of two (2) · Issue #47701 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[symfony/mailjet-mailer] JSON payload for X-MJ-Vars only allows for a max depth of two (2) #47701

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
nurtext opened this issue Sep 26, 2022 · 0 comments · Fixed by #47703
Closed

Comments

@nurtext
Copy link
Contributor
nurtext commented Sep 26, 2022

Symfony version(s) affected

6.1.*

Description

When using der MailJet Mailer component using the MailJet API in conjunction with template variables, the MailJet component only allows for a max depth of two (2), thus we're getting the following error while trying to send emails:

JsonException
in vendor/symfony/mailjet-mailer/Transport/MailjetApiTransport.php (line 204)

199    private function castCustomHeader(string $value, string $type)
200   {
201        return match ($type) {
202            'bool' => filter_var($value, \FILTER_VALIDATE_BOOLEAN),
203            'int' => (int) $value,
204            'json' => json_decode($value, true, 2, \JSON_THROW_ON_ERROR), <--
205            'string' => $value,
206       };
207    }
208 }

When using the MailJet PHP API (https://github.com/mailjet/mailjet-apiv3-php) there's no limitation to the depth of the variable template payload.

How to reproduce

  1. Create a free MailJet account for using the MailJet API
  2. Create a new Symfony app
  3. Require both symfony/mailer and symfony/mailjet-mailer using composer
  4. Configure the MAILER_DSN to use the MailJet API transport as described in the documentation https://symfony.com/doc/current/mailer.html#using-a-3rd-party-transport
  5. Try to send an email that uses MailJet templates and add a multi-dimensional array for template variables

Example:

$templateId = 1337;

$templateVars = [
    'foo' => [
        'bar' => 'baz',
    ],
];

$email = (new Symfony\Component\Mime\Email())
    ->from('foo@localhost')
    ->to('bar@localhost')
    ->subject('Test email');
    
$email->text('Ignored, because using MailJet templates');

$email
    ->getHeaders()
    ->addTextHeader('X-MJ-TemplateLanguage', 'true')
    ->addTextHeader('X-MJ-TemplateID', $templateId)
    ->addTextHeader('X-MJ-Vars', \json_encode($templateVars));
    
$this->mailer->send($email);

Possible Solution

Remove the limitation that allows for only a max depth of 2 levels here: https://github.com/symfony/mailjet-mailer/blob/6.1/Transport/MailjetApiTransport.php#L204

Additional Context

No response

@nurtext nurtext added the Bug label Sep 26, 2022
nurtext added a commit to nurtext/symfony that referenced this issue Sep 27, 2022
@xabbuh xabbuh added the Mailer label Sep 28, 2022
@fabpot fabpot closed this as completed Sep 29, 2022
fabpot added a commit that referenced this issue Sep 29, 2022
…epths (nurtext)

This PR was merged into the 6.1 branch.

Discussion
----------

[Mailer][Mailjet] Apply the default value of 512 for max depths

| Q             | A
| ------------- | ---
| Branch?       | 6.1
| Bug fix?      | yes
| New feature?  | no
| Deprecations? | no
| Tickets       | Fix #47701
| License       | MIT
| Doc PR        | n/a

Applies the default value of 512 for max depths when using PHP's json_decode() function.

See #47701 for more details.

Commits
-------

7832d77 [symfony/mailjet-mailer] Fix bug #47701
xabbuh added a commit that referenced this issue Oct 1, 2022
* 6.1:
  fix merge
  [FrameworkBundle] Allow to specify `null` for exception mapping configuration values
  Fix BinaryFileResponse content type detection logic
  [Notifier] [Expo] Throw exception on error-response from expo api
  Bump Symfony version to 6.1.6
  Update VERSION for 6.1.5
  Update CHANGELOG for 6.1.5
  Bump Symfony version to 6.0.14
  Update VERSION for 6.0.13
  Update CHANGELOG for 6.0.13
  Bump Symfony version to 5.4.14
  Update VERSION for 5.4.13
  Update CHANGELOG for 5.4.13
  Bump Symfony version to 4.4.47
  Update VERSION for 4.4.46
  Update CONTRIBUTORS for 4.4.46
  Update CHANGELOG for 4.4.46
  [Security] Fix login url matching when app is not run with url rewriting or from a sub folder
  [symfony/mailjet-mailer] Fix bug #47701
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants
0