Skip to content

Commit 970d67a

Browse files
authored
Merge pull request #6213 from magento-tsg/MC-36005
[Condor] MC-36005: [Backport for 2.3.x] Customer REST API leaks information
2 parents 001994d + 4570446 commit 970d67a

File tree

12 files changed

+695
-3
lines changed

12 files changed

+695
-3
lines changed
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\Customer\Model\Address\Validator;
9+
10+
use Magento\Customer\Model\Address\AbstractAddress;
11+
use Magento\Customer\Model\Address\ValidatorInterface;
12+
use Magento\Customer\Model\AddressFactory;
13+
use Magento\Quote\Api\Data\AddressInterface as QuoteAddressInterface;
14+
15+
/**
16+
* Validates that current Address is related to given Customer.
17+
*/
18+
class Customer implements ValidatorInterface
19+
{
20+
/**
21+
* @var AddressFactory
22+
*/
23+
private $addressFactory;
24+
25+
/**
26+
* @param AddressFactory $addressFactory
27+
*/
28+
public function __construct(AddressFactory $addressFactory)
29+
{
30+
$this->addressFactory = $addressFactory;
31+
}
32+
33+
/**
34+
* @inheritDoc
35+
*/
36+
public function validate(AbstractAddress $address): array
37+
{
38+
$errors = [];
39+
$addressId = $address instanceof QuoteAddressInterface ? $address->getCustomerAddressId() : $address->getId();
40+
if ($addressId !== null) {
41+
$addressCustomerId = (int) $address->getCustomerId();
42+
$originalAddressCustomerId = (int) $this->addressFactory->create()
43+
->load($addressId)
44+
->getCustomerId();
45+
46+
if ($originalAddressCustomerId !== 0 && $originalAddressCustomerId !== $addressCustomerId) {
47+
$errors[] = __(
48+
'Provided customer ID "%customer_id" isn\'t related to current customer address.',
49+
['customer_id' => $addressCustomerId]
50+
);
51+
}
52+
}
53+
54+
return $errors;
55+
}
56+
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\Customer\Model\Webapi;
9+
10+
use Magento\Authorization\Model\UserContextInterface;
11+
use Magento\Customer\Api\CustomerRepositoryInterface;
12+
use Magento\Framework\Webapi\Rest\Request\ParamOverriderInterface;
13+
14+
/**
15+
* Replaces a "%customer_group_id%" value with the real customer id
16+
*/
17+
class ParamOverriderCustomerGroupId implements ParamOverriderInterface
18+
{
19+
/**
20+
* @var UserContextInterface
21+
*/
22+
private $userContext;
23+
24+
/**
25+
* @var CustomerRepositoryInterface
26+
*/
27+
private $customerRepository;
28+
29+
/**
30+
* @param UserContextInterface $userContext
31+
* @param CustomerRepositoryInterface $customerRepository
32+
*/
33+
public function __construct(UserContextInterface $userContext, CustomerRepositoryInterface $customerRepository)
34+
{
35+
$this->userContext = $userContext;
36+
$this->customerRepository = $customerRepository;
37+
}
38+
39+
/**
40+
* @inheritDoc
41+
*/
42+
public function getOverriddenValue()
43+
{
44+
if ((int) $this->userContext->getUserType() === UserContextInterface::USER_TYPE_CUSTOMER) {
45+
return $this->customerRepository->getById($this->userContext->getUserId())->getGroupId();
46+
}
47+
48+
return null;
49+
}
50+
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\Customer\Model\Webapi;
9+
10+
use Magento\Authorization\Model\UserContextInterface;
11+
use Magento\Customer\Api\CustomerRepositoryInterface;
12+
use Magento\Framework\Webapi\Rest\Request\ParamOverriderInterface;
13+
14+
/**
15+
* Replaces a "%customer_store_id%" value with the real customer id
16+
*/
17+
class ParamOverriderCustomerStoreId implements ParamOverriderInterface
18+
{
19+
/**
20+
* @var UserContextInterface
21+
*/
22+
private $userContext;
23+
24+
/**
25+
* @var CustomerRepositoryInterface
26+
*/
27+
private $customerRepository;
28+
29+
/**
30+
* @param UserContextInterface $userContext
31+
* @param CustomerRepositoryInterface $customerRepository
32+
*/
33+
public function __construct(UserContextInterface $userContext, CustomerRepositoryInterface $customerRepository)
34+
{
35+
$this->userContext = $userContext;
36+
$this->customerRepository = $customerRepository;
37+
}
38+
39+
/**
40+
* @inheritDoc
41+
*/
42+
public function getOverriddenValue()
43+
{
44+
if ((int) $this->userContext->getUserType() === UserContextInterface::USER_TYPE_CUSTOMER) {
45+
return $this->customerRepository->getById($this->userContext->getUserId())->getStoreId();
46+
}
47+
48+
return null;
49+
}
50+
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\Customer\Model\Webapi;
9+
10+
use Magento\Authorization\Model\UserContextInterface;
11+
use Magento\Customer\Api\CustomerRepositoryInterface;
12+
use Magento\Framework\Webapi\Rest\Request\ParamOverriderInterface;
13+
14+
/**
15+
* Replaces a "%customer_website_id%" value with the real customer id
16+
*/
17+
class ParamOverriderCustomerWebsiteId implements ParamOverriderInterface
18+
{
19+
/**
20+
* @var UserContextInterface
21+
*/
22+
private $userContext;
23+
24+
/**
25+
* @var CustomerRepositoryInterface
26+
*/
27+
private $customerRepository;
28+
29+
/**
30+
* @param UserContextInterface $userContext
31+
* @param CustomerRepositoryInterface $customerRepository
32+
*/
33+
public function __construct(UserContextInterface $userContext, CustomerRepositoryInterface $customerRepository)
34+
{
35+
$this->userContext = $userContext;
36+
$this->customerRepository = $customerRepository;
37+
}
38+
39+
/**
40+
* @inheritDoc
41+
*/
42+
public function getOverriddenValue()
43+
{
44+
if ((int) $this->userContext->getUserType() === UserContextInterface::USER_TYPE_CUSTOMER) {
45+
return $this->customerRepository->getById($this->userContext->getUserId())->getWebsiteId();
46+
}
47+
48+
return null;
49+
}
50+
}

0 commit comments

Comments
 (0)