Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/CXml/Authentication/SimpleSharedSecretAuthenticator.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ public function __construct(private string $sharedSecret)

public function authenticate(Header $header, Context $context): void
{
if ($this->sharedSecret !== $header->sender->credential->getSharedSecret()) {
// use hash_equals() for constant-time comparison to prevent timing attacks
if (!hash_equals($this->sharedSecret, (string)$header->sender->credential->getSharedSecret())) {
throw new CXmlAuthenticationInvalidException($header->sender->credential);
}
}
Expand Down
1 change: 0 additions & 1 deletion src/CXml/Builder/OrderRequestBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,6 @@ public static function fromPunchOutOrderMessage(
$orderDate,
$currency,
$language,
null,
);

$orb->setShipTo($punchOutOrderMessage->punchOutOrderMessageHeader->getShipTo());
Expand Down
3 changes: 2 additions & 1 deletion src/CXml/Credential/Registry.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ public function authenticate(Header $header, Context $context): void
$senderCredential->identity,
);

if ($baseCredential->getSharedSecret() !== $senderCredential->getSharedSecret()) {
// use hash_equals() for constant-time comparison to prevent timing attacks
if (!hash_equals((string)$baseCredential->getSharedSecret(), (string)$senderCredential->getSharedSecret())) {
throw new CXmlAuthenticationInvalidException($senderCredential);
}
}
Expand Down
15 changes: 10 additions & 5 deletions src/CXml/Endpoint.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,13 @@ public function __construct(
*/
public function parseAndProcessStringAsCXml(string $xml, ?Context $context = null): ?CXml
{
$this->logger->info('Processing incoming CXml message', ['xml' => $xml]);
$this->logger->info('Processing incoming CXml message', ['xml' => $this->removeSharedSecret($xml)]);

// validate
try {
$this->dtdValidator->validateAgainstDtd($xml);
} catch (CXmlInvalidException $cXmlInvalidException) {
$this->logger->error('Incoming CXml was invalid (via DTD)', ['xml' => $xml]);
$this->logger->error('Incoming CXml was invalid (via DTD)', ['xml' => $this->removeSharedSecret($xml)]);

throw $cXmlInvalidException;
}
Expand All @@ -47,7 +47,7 @@ public function parseAndProcessStringAsCXml(string $xml, ?Context $context = nul
try {
$cxml = $this->serializer->deserialize($xml);
} catch (RuntimeException $runtimeException) {
$this->logger->error('Error while deserializing xml to CXml: ' . $runtimeException->getMessage(), ['xml' => $xml]);
$this->logger->error('Error while deserializing xml to CXml: ' . $runtimeException->getMessage(), ['xml' => $this->removeSharedSecret($xml)]);

throw new CXmlInvalidException('Error while deserializing xml: ' . $runtimeException->getMessage(), $xml, $runtimeException);
}
Expand All @@ -56,13 +56,18 @@ public function parseAndProcessStringAsCXml(string $xml, ?Context $context = nul
try {
$result = $this->processor->process($cxml, $context);
} catch (CXmlException $cXmlException) {
$this->logger->error('Error while processing valid CXml: ' . $cXmlException->getMessage(), ['xml' => $xml]);
$this->logger->error('Error while processing valid CXml: ' . $cXmlException->getMessage(), ['xml' => $this->removeSharedSecret($xml)]);

throw $cXmlException;
}

$this->logger->info('Success after processing incoming CXml message', ['xml' => $xml]);
$this->logger->info('Success after processing incoming CXml message', ['xml' => $this->removeSharedSecret($xml)]);

return $result;
}

private function removeSharedSecret(string $xml): string
{
return (string)preg_replace('/<SharedSecret>.*?<\/SharedSecret>/s', '<SharedSecret>***REDACTED***</SharedSecret>', $xml);
}
}
1 change: 1 addition & 0 deletions src/CXml/Model/BusinessPartner.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
class BusinessPartner
{
use IdReferencesTrait;

final public const ROLE_SOLD_TO = 'soldTo';

final public const ROLE_SHIP_FROM = 'shipFrom';
Expand Down
2 changes: 1 addition & 1 deletion src/CXml/Model/Response/ProfileResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class ProfileResponse implements ResponsePayloadInterface
/**
* @var Transaction[]
*/
#[Serializer\XmlList(inline: true, entry: 'Transaction')]
#[Serializer\XmlList(entry: 'Transaction', inline: true)]
#[Serializer\Type('array<CXml\Model\Transaction>')]
private array $transactions = [];

Expand Down
3 changes: 2 additions & 1 deletion src/CXml/Validation/DtdValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ public function validateAgainstDtd(string $xml): void
$internalErrors = libxml_use_internal_errors(true);

$old = new DOMDocument();
$old->loadXML($xml);
// disable network access for security reasons
$old->loadXML($xml, LIBXML_NONET);

$this->validateAgainstMultipleDtd($this->pathToDtds, $old);

Expand Down
2 changes: 1 addition & 1 deletion src/CXml/Validation/Exception/CXmlInvalidException.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public static function fromLibXmlError($libXmlError, string $xml): self

return new self(
$message,
$xml,
(string)preg_replace('/<SharedSecret>.*?<\/SharedSecret>/s', '<SharedSecret>***REDACTED***</SharedSecret>', $xml),
);
}
}
2 changes: 2 additions & 0 deletions tests/CXmlTest/Handling/HandlerTest.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace CXmlTest\Handling;

use CXml\Authentication\SimpleSharedSecretAuthenticator;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace CXmlTest\Model;

use CXml\Builder;
Expand Down
1 change: 0 additions & 1 deletion tests/CXmlTest/Model/SerializerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,6 @@ public function testSerializeSimpleResponse(): void
),
new Response(
new Status(200, 'OK', 'Ping Response CXml'),
null,
),
);

Expand Down