Issues (116)

Security Analysis    not enabled

This project does not seem to handle request data directly as such no vulnerable execution paths were found.

  Cross-Site Scripting
Cross-Site Scripting enables an attacker to inject code into the response of a web-request that is viewed by other users. It can for example be used to bypass access controls, or even to take over other users' accounts.
  File Exposure
File Exposure allows an attacker to gain access to local files that he should not be able to access. These files can for example include database credentials, or other configuration files.
  File Manipulation
File Manipulation enables an attacker to write custom data to files. This potentially leads to injection of arbitrary code on the server.
  Object Injection
Object Injection enables an attacker to inject an object into PHP code, and can lead to arbitrary code execution, file exposure, or file manipulation attacks.
  Code Injection
Code Injection enables an attacker to execute arbitrary code on the server.
  Response Splitting
Response Splitting can be used to send arbitrary responses.
  File Inclusion
File Inclusion enables an attacker to inject custom files into PHP's file loading mechanism, either explicitly passed to include, or for example via PHP's auto-loading mechanism.
  Command Injection
Command Injection enables an attacker to inject a shell command that is execute with the privileges of the web-server. This can be used to expose sensitive data, or gain access of your server.
  SQL Injection
SQL Injection enables an attacker to execute arbitrary SQL code on your database server gaining access to user data, or manipulating user data.
  XPath Injection
XPath Injection enables an attacker to modify the parts of XML document that are read. If that XML document is for example used for authentication, this can lead to further vulnerabilities similar to SQL Injection.
  LDAP Injection
LDAP Injection enables an attacker to inject LDAP statements potentially granting permission to run unauthorized queries, or modify content inside the LDAP tree.
  Header Injection
  Other Vulnerability
This category comprises other attack vectors such as manipulating the PHP runtime, loading custom extensions, freezing the runtime, or similar.
  Regex Injection
Regex Injection enables an attacker to execute arbitrary code in your PHP process.
  XML Injection
XML Injection enables an attacker to read files on your local filesystem including configuration files, or can be abused to freeze your web-server process.
  Variable Injection
Variable Injection enables an attacker to overwrite program variables with custom data, and can lead to further vulnerabilities.
Unfortunately, the security analysis is currently not available for your project. If you are a non-commercial open-source project, please contact support to gain access.

src/Bibs/Bib.php (1 issue)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
namespace Scriptotek\Alma\Bibs;
4
5
use Danmichaelo\QuiteSimpleXMLElement\QuiteSimpleXMLElement;
6
use Scriptotek\Alma\Client;
7
use Scriptotek\Alma\Exception\NoLinkedNetworkZoneRecordException;
8
use Scriptotek\Alma\Model\LazyResource;
9
use Scriptotek\Alma\Users\Requests;
10
use Scriptotek\Marc\Record as MarcRecord;
11
use Scriptotek\Sru\Record as SruRecord;
12
13
/**
14
 * A single Bib resource.
15
 */
16
class Bib extends LazyResource
17
{
18
    /** @var string */
19
    public $mms_id;
20
21
    /* @var Holdings */
22
    public $holdings;
23
24
    /* @var Portfolios */
25
    public $portfolios;
26
27
    /* @var Representations */
28
    public $representations;
29
30
    /* @var ElectronicCollections */
31
    public $electronic_collections;
32
33
    /* @var MarcRecord */
34
    protected $_marc;
35
36
    /** @var Requests */
37
    public $requests;
38
39
    public function __construct(Client $client = null, $mms_id = null)
40
    {
41
        parent::__construct($client);
42
        $this->mms_id = $mms_id;
43
        $this->holdings = Holdings::make($this->client, $this);
44
        $this->portfolios = Portfolios::make($this->client, $this);
45
        $this->representations = Representations::make($this->client, $this);
46
        $this->electronic_collections = ElectronicCollections::make($this->client, $this);
47
        $this->requests = Requests::make($this->client, $this->url('/requests'));
48
    }
49
50
    /**
51
     * Get the model data. This API does not support JSON for editing,
52
     * so we fetch XML instead.
53
     */
54
    protected function fetchData()
55
    {
56
        return $this->client->getXML($this->url());
0 ignored issues
show
Bug Best Practice introduced by
The return type of return $this->client->getXML($this->url()); (Danmichaelo\QuiteSimpleX...t\QuiteSimpleXMLElement) is incompatible with the return type of the parent method Scriptotek\Alma\Model\LazyResource::fetchData of type stdClass.

If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.

Let’s take a look at an example:

class Author {
    private $name;

    public function __construct($name) {
        $this->name = $name;
    }

    public function getName() {
        return $this->name;
    }
}

abstract class Post {
    public function getAuthor() {
        return 'Johannes';
    }
}

class BlogPost extends Post {
    public function getAuthor() {
        return new Author('Johannes');
    }
}

class ForumPost extends Post { /* ... */ }

function my_function(Post $post) {
    echo strtoupper($post->getAuthor());
}

Our function my_function expects a Post object, and outputs the author of the post. The base class Post returns a simple string and outputting a simple string will work just fine. However, the child class BlogPost which is a sub-type of Post instead decided to return an object, and is therefore violating the SOLID principles. If a BlogPost were passed to my_function, PHP would not complain, but ultimately fail when executing the strtoupper call in its body.

Loading history...
57
    }
58
59
    /**
60
     * Load MARC record onto this Bib object. Chainable method.
61
     *
62
     * @param string $xml
63
     *
64
     * @return Bib
65
     */
66
    public function setMarcRecord($xml)
67
    {
68
        $this->_marc = MarcRecord::fromString($xml);
69
        // Note: do not marc as initialized, since we miss some other data from the Bib record. Oh, Alma :/
70
71
        return $this;
72
    }
73
74
    /**
75
     * Initialize from SRU record without having to fetch the Bib record.
76
     *
77
     * @param SruRecord   $record
78
     * @param Client|null $client
79
     *
80
     * @return Bib
81
     */
82
    public static function fromSruRecord(SruRecord $record, Client $client = null)
83
    {
84
        $record->data->registerXPathNamespace('marc', 'http://www.loc.gov/MARC21/slim');
85
        $mmsId = $record->data->text('.//marc:controlfield[@tag="001"]');
86
87
        return (new self($client, $mmsId))
88
            ->setMarcRecord($record->data->asXML());
89
    }
90
91
    /**
92
     * For backwards-compability.
93
     */
94
    public function getHoldings()
95
    {
96
        return $this->holdings;
97
    }
98
99
    /**
100
     * Save the MARC record.
101
     */
102
    public function save()
103
    {
104
        // If initialized from an SRU record, we need to fetch the
105
        // remaining parts of the Bib record.
106
        $this->init();
107
108
        // Inject the MARC record
109
        $marcXml = new QuiteSimpleXMLElement($this->_marc->toXML('UTF-8', false, false));
110
        $this->data->first('record')->replace($marcXml);
111
112
        // Serialize
113
        $newData = $this->data->asXML();
114
115
        // Alma doesn't like namespaces
116
        $newData = str_replace(' xmlns="http://www.loc.gov/MARC21/slim"', '', $newData);
117
118
        return $this->client->putXML($this->url(), $newData);
119
    }
120
121
    /**
122
     * Get the MMS ID of the linked record in network zone.
123
     */
124
    public function getNzMmsId()
125
    {
126
        // If initialized from an SRU record, we need to fetch the
127
        // remaining parts of the Bib record.
128
        $this->init();
129
130
        $nz_mms_id = $this->data->text("linked_record_id[@type='NZ']");
131
        if (!$nz_mms_id) {
132
            throw new NoLinkedNetworkZoneRecordException("Record $this->mms_id is not linked to a network zone record.");
133
        }
134
135
        return $nz_mms_id;
136
    }
137
138
    /**
139
     * Get the Bib of the linked record in network zone.
140
     */
141
    public function getNzRecord()
142
    {
143
        return $this->client->nz->bibs->get($this->getNzMmsId());
144
    }
145
146
    /**
147
     * Returns the MARC record. Load it if we don't have it yet.
148
     */
149
    public function getRecord()
150
    {
151
        if (is_null($this->_marc)) {
152
            $this->init();
153
        }
154
155
        return $this->_marc;
156
    }
157
158
    /**
159
     * Called when data is available to be processed.
160
     *
161
     * @param mixed $data
162
     */
163
    protected function onData($data)
164
    {
165
        $this->setMarcRecord($data->first('record')->asXML());
166
    }
167
168
    /**
169
     * Check if we have the full representation of our data object.
170
     *
171
     * @param $data
172
     *
173
     * @return bool
174
     */
175
    protected function isInitialized($data)
176
    {
177
        return is_a($data, QuiteSimpleXMLElement::class) && $data->has('record');
178
    }
179
180
    /**
181
     * Generate the base URL for this resource.
182
     *
183
     * @return string
184
     */
185
    protected function urlBase()
186
    {
187
        return "/bibs/{$this->mms_id}";
188
    }
189
}
190