OpenMage / magento-lts

Official OpenMage LTS codebase | Migrate easily from Magento Community Edition in minutes! Download the source code for free or contribute to OpenMage LTS | Security vulnerability patches, bug fixes, performance improvements and more.
https://www.openmage.org
Open Software License 3.0
869 stars 436 forks source link

Access denied when connecting via SOAP #3149

Open gbgssoftware opened 1 year ago

gbgssoftware commented 1 year ago

Preconditions (*)

1.OpenMage 20.1.0-rc3 2.PHP 7.4 Apache 2.4

Steps to reproduce (*)

1.Open http://site.loc/api/v2_soap/index in browser 2.

Expected result (*)

1.URL can be opened 2.

Actual result (*)

  1. ` WSDL SOAP-ERROR: Parsing WSDL: Couldn't load from 'http://site.loc/api/v2_soap/index/?wsdl=1' : Premature end of data in tag operation line 374 ` I created a new user with and a new role with full access. I checked all the urn and they are all set to the value: urn:OpenMage I add the .htaccess file with this line: php_value default_socket_timeout 6000

I read issue: #1723

I did this test: I created a tes file in php:

<?php
$mage_user = 'user';
$mage_api_key = 'pass';
$mage_url = 'http://site.loc/api/soap/?wsdl';
$ini = ini_set("soap.wsdl_cache_enabled", 0);
$client = new SoapClient( $mage_url ,array('trace' => true));
try {
    print_r($client->__getFunctions());
    $session_id = $client->login($mage_user, $mage_api_key);
    $result = $client->call( $session_id, 'directory_country.list' );
    var_dump($result);
} catch (Exception $e) {
    var_dump($e->getMessage());
    echo "<br>Request Headers:<br>", htmlentities($client->__getLastRequestHeaders()), "<br>";
    echo "<br>Request :<br>", htmlentities($client->__getLastRequest()), "<br>";
    echo "<br>Response Headers:<br>", htmlentities($client->__getLastResponseHeaders()), "<br>";
    echo "<br>Response body:<br>", htmlentities($client->__getLastResponse()), "<br>";
}

result:

Array
(
    [0] => anyType call(string $sessionId, string $resourcePath, anyType $args)
    [1] => FixedArray multiCall(string $sessionId, FixedArray $calls, anyType $options)
    [2] => boolean endSession(string $sessionId)
    [3] => string login(string $username, string $apiKey)
    [4] => string startSession()
    [5] => FixedArray resources(string $sessionId)
    [6] => FixedArray globalFaults(string $sessionId)
    [7] => FixedArray resourceFaults(string $resourceName, string $sessionId)
)
string(14) "Access denied."
<br>Request Headers:<br>POST /api.php?type=soap HTTP/1.1
Host: site.loc
Connection: Keep-Alive
User-Agent: PHP-SOAP/7.4.33
Content-Type: text/xml; charset=utf-8
SOAPAction: &quot;urn:Action&quot;
Content-Length: 612

<br><br>Request :<br>&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
&lt;SOAP-ENV:Envelope xmlns:SOAP-ENV=&quot;http://schemas.xmlsoap.org/soap/envelope/&quot; xmlns:ns1=&quot;urn:OpenMage&quot; xmlns:xsd=&quot;http://www.w3.org/2001/XMLSchema&quot; xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot; xmlns:SOAP-ENC=&quot;http://schemas.xmlsoap.org/soap/encoding/&quot; SOAP-ENV:encodingStyle=&quot;http://schemas.xmlsoap.org/soap/encoding/&quot;&gt;&lt;SOAP-ENV:Body&gt;&lt;ns1:call&gt;&lt;sessionId xsi:type=&quot;xsd:string&quot;&gt;bbdd9f9364a76c80116e5749396b3cd7&lt;/sessionId&gt;&lt;resourcePath xsi:type=&quot;xsd:string&quot;&gt;directory_country.list&lt;/resourcePath&gt;&lt;args xsi:nil=&quot;true&quot;/&gt;&lt;/ns1:call&gt;&lt;/SOAP-ENV:Body&gt;&lt;/SOAP-ENV:Envelope&gt;
<br><br>Response Headers:<br>HTTP/1.1 200 OK
Date: Wed, 05 Apr 2023 18:19:47 GMT
Server: Apache/2.4.54 (Debian)
Content-Length: 267
Vary: Accept-Encoding
Keep-Alive: timeout=5, max=99
Connection: Keep-Alive
Content-Type: text/xml; charset=UTF-8
<br><br>Response body:<br>&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
&lt;SOAP-ENV:Envelope xmlns:SOAP-ENV=&quot;http://schemas.xmlsoap.org/soap/envelope/&quot;&gt;&lt;SOAP-ENV:Body&gt;&lt;SOAP-ENV:Fault&gt;&lt;faultcode&gt;2&lt;/faultcode&gt;&lt;faultstring&gt;Access denied.&lt;/faultstring&gt;&lt;/SOAP-ENV:Fault&gt;&lt;/SOAP-ENV:Body&gt;&lt;/SOAP-ENV:Envelope&gt;
fballiano commented 1 year ago

is it possible that a broken wsdl is cached? https://stackoverflow.com/questions/303488/in-php-how-can-you-clear-a-wsdl-cache

gbgssoftware commented 1 year ago

Edit php.ini file, search for soap.wsdl_cache_enabled and set the value to 0 The problem occurs

elidrissidev commented 1 year ago

Access denied is a generic error and there are multiple cases where it would get thrown. Do you have logging enabled? If so check var/log/exception.log for the full stack trace.

gbgssoftware commented 1 year ago

In /var/log/exception.log I don't have any API related errors. I have an error two days ago.

elidrissidev commented 1 year ago

Try updating the line below to add the full error message: https://github.com/OpenMage/magento-lts/blob/6851e17f5f74f82241762b8f1c0779e6f0d54b51/app/code/core/Mage/Api/Model/Server/Handler/Abstract.php#L214

- return $this->_fault('access_denied');
+ return $this->_fault('access_denied', $e->getMessage());
gbgssoftware commented 1 year ago

I have inserted several points for the logs. Access Denied occurs on line 259.

I modified like this: ` if (!isset($resources->$resourceName->public) && isset($resources->$resourceName->acl) && !$this->_isAllowed((string)$resources->$resourceName->acl) ) { Mage::log(' Ent 2', null, 'error.log', true); Mage::log((string)$resources->$resourceName, null, 'error.log', true) Mage::log((string)$resources->$resourceName->public, null, 'error.log', true); Mage::log((string)$resources->$resourceName->acl, null, 'error.log', true); return $this->_fault('access_denied'); }

The content of error.log is:`

`2023-04-06T18:00:46+00:00 DEBUG (7): Ent 2

2023-04-06T18:00:46+00:00 DEBUG (7):

2023-04-06T18:00:46+00:00 DEBUG (7):

`

Is it correct that $resources->$resourceName is empty? And why does $resources->$resourceName->acl have a value of directory/country?

gbgssoftware commented 1 year ago

I tried now in roles to put ALL and it works. Custom throws me an error

S0FTWEX commented 1 year ago

Following steps to reproduce, I got this error: PHP Fatal error: SOAP-ERROR: Parsing WSDL: Unexpected WSDL element <schema> in /vendor/shardj/zf1-future/library/Zend/Soap/Server.php on line 814'

DegrizNet commented 2 weeks ago

Following steps to reproduce, I got this error: PHP Fatal error: SOAP-ERROR: Parsing WSDL: Unexpected WSDL element <schema> in /vendor/shardj/zf1-future/library/Zend/Soap/Server.php on line 814'

I had same problem and it was because there was module stil using ""

to fix in terminal find all schema instances like this: grep -r '<schema' .

You will get sothing like this: ... ./app/code/core/Mage/Catalog/etc/wsdl.xml: ./app/code/local/TM/CheckoutFields/etc/wsdl.xml: ...

And if you change in last file "urn:Magento" to "urn:OpenMage" issue is fixed.