Issues (52)

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.

server/app/Models/Article.php (1 issue)

Labels
Severity

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
/**
4
 * This file is part of laravel.su package.
5
 *
6
 * For the full copyright and license information, please view the LICENSE
7
 * file that was distributed with this source code.
8
 */
9
declare(strict_types=1);
10
11
namespace App\Models;
12
13
use Carbon\Carbon;
14
use Illuminate\Support\Str;
15
use Illuminate\Database\Eloquent\Model;
16
use Illuminate\Database\Eloquent\Builder;
17
use Illuminate\Contracts\Auth\Authenticatable;
18
use Illuminate\Database\Eloquent\Relations\MorphTo;
19
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
20
21
/**
22
 * Class Article.
23
 */
24
class Article extends Model
25
{
26
    /**
27
     * Published date and time field name.
28
     */
29
    private const PUBLISHED_AT = 'published_at';
30
31
    /**
32
     * Directory of article images.
33
     */
34
    public const DEFAULT_IMAGE_PATH = '/static/articles/';
35
36
    /**
37
     * @var array
38
     */
39
    protected $dates = [
40
        self::PUBLISHED_AT,
41
    ];
42
43
    /**
44
     * @var string
45
     */
46
    protected $table = 'articles';
47
48
    /**
49
     * @var array
50
     */
51
    protected $fillable = [
52
        'user_id', 'title', 'image', 'content_source',
53
        'status', 'published_at',
54
    ];
55
56
    /**
57
     * @param  Builder $builder
58
     * @return Builder
59
     */
60
    public static function scopeLatestPublished(Builder $builder): Builder
61
    {
62
        return $builder
63
            ->with('user')
64
            ->with('tags')
65
            ->latest('published_at')
66
            ->published();
67
    }
68
69
    /**
70
     * @param  Builder $builder
71
     * @return Builder
72
     */
73
    public static function scopeLatest(Builder $builder): Builder
74
    {
75
        return $builder->orderBy('published_at', 'desc');
0 ignored issues
show
The method orderBy() does not exist on Illuminate\Database\Eloquent\Builder. Did you maybe mean enforceOrderBy()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
76
    }
77
78
    /**
79
     * @param  Builder $builder
80
     * @return Builder
81
     */
82
    public static function scopePublished(Builder $builder): Builder
83
    {
84
        return $builder
85
            ->where('published_at', '<=', Carbon::now())
86
            ->where('status', Article\Status::PUBLISHED);
87
    }
88
89
    /**
90
     * @param  Builder $builder
91
     * @return Builder
92
     */
93
    public static function scopePublishedByBot(Builder $builder): Builder
94
    {
95
        return $builder
96
            ->where('user_type', Bot::class);
97
    }
98
99
    /**
100
     * @param  Authenticatable|User|null $user
101
     * @return bool
102
     */
103
    public function isAllowedForUser(?Authenticatable $user): bool
104
    {
105
        $isAuthor = $user === null ? false : ($this->user->id === $user->getAuthIdentifier());
106
107
        $isPublished = $this->status === Article\Status::PUBLISHED;
108
109
        $isAllowPublishedTime = $this->published_at <= Carbon::now();
110
111
        return $isAuthor || ($isPublished && $isAllowPublishedTime);
112
    }
113
114
    /**
115
     * @return string
116
     */
117
    public function getImageUrlAttribute(): string
118
    {
119
        if (Str::startsWith($this->image, ['http:', 'https:', '//'])) {
120
            return $this->image;
121
        }
122
123
        return static::DEFAULT_IMAGE_PATH . $this->image;
124
    }
125
126
    /**
127
     * @return string
128
     */
129
    public function getCapitalizeTitleAttribute(): string
130
    {
131
        return Str::ucfirst($this->title);
132
    }
133
134
    /**
135
     * @return string
136
     */
137
    public function getNicePublishedDateAttribute(): string
138
    {
139
        if ($this->published_at > Carbon::now()->subMonth()) {
140
            return $this->published_at->diffForHumans();
141
        }
142
143
        return $this->published_at->toDateTimeString();
144
    }
145
146
    /**
147
     * @return MorphTo
148
     */
149
    public function user(): MorphTo
150
    {
151
        return $this->morphTo();
152
    }
153
154
    /**
155
     * @return BelongsToMany
156
     */
157
    public function tags(): BelongsToMany
158
    {
159
        return $this->belongsToMany(Tag::class, 'article_tags');
160
    }
161
}
162