Skip to content

Undefined array key "contact" in Client.php:362 causes TypeError #78

@nintech-sudo

Description

@nintech-sudo

Description:

I encountered a TypeError when using the Client::getAccount() method in Client.php (line 362). The error occurs when the contact key is missing or empty in the Let's Encrypt API response, causing null to be passed to Account::__construct(), which expects an array.

Steps to Reproduce:

Initialize Client with a configuration containing contact (e.g., ['mailto:admin@ultimas.io.vn']).
Call createOrder(), which triggers getAccount().
The error appears if the API response lacks the contact key.

Error Log:

PHP Warning: Undefined array key "contact" in .../Client.php on line 362
PHP Fatal error: Uncaught TypeError: Afosto\Acme\Data\Account::__construct(): Argument #1 ($contact) must be of type array, null given```

Cause:
The code assumes $data['contact'] exists without validation:
return new Account($data['contact'], $date, ($data['status'] == 'valid'), $accountURL);

Fix:
Modify getAccount() to use $this->config['contact'] as fallback:

{
    $response = $this->request(
        $this->getUrl(self::DIRECTORY_NEW_ACCOUNT),
        $this->signPayloadJWK(
            ['onlyReturnExisting' => true],
            $this->getUrl(self::DIRECTORY_NEW_ACCOUNT)
        )
    );
    $data = json_decode((string)$response->getBody(), true);
    $accountURL = $response->getHeaderLine('Location');
    $date = (new \DateTime())->setTimestamp(strtotime($data['createdAt']));
    $contact = isset($data['contact']) && is_array($data['contact']) ? $data['contact'] : $this->getOption('contact', ['mailto:' . $this->getOption('username')]);
    error_log("Contact before Account creation: " . json_encode($contact));
    return new Account($contact, $date, ($data['status'] == 'valid'), $accountURL);
}```

Request for Fix:

Please address this issue by adding a check for the existence of $data['contact'] in the getAccount() method. I suggest using $this->config['contact'] as a fallback if $data['contact'] is missing or not an array.

Thank you for your support!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions