Issues (1)

Security Analysis    no request data  

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/LineNotify.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 KS\Line;
4
5
use GuzzleHttp\Client;
6
7
/**
8
 * A simple class to send text message, image and Line sticker on Line notify
9
 * 
10
 * https://notify-bot.line.me/doc/en/
11
 * 
12
 * @property string $token Line notify token
13
 * @property \GuzzleHttp\Client $http Guzzle Http Client instance for send Http request
14
 */
15
class LineNotify {
16
17
  const API_URL = 'https://notify-api.line.me/api/notify';
18
19
  private $token = null;
20
  private $http = null;
21
  
22
  /**
23
   * Initialize class with Line notify token string
24
   * 
25
   * @param string $token the token of Line notify
26
   */
27
  public function __construct($token) {
28
29
    $this->token = $token;
30
    $this->http = new Client();
31
  }
32
  
33
  /**
34
   * Set token Line notify that want to send message
35
   * 
36
   * @param string $token the token of Line notify
37
   */
38 1
  public function setToken($token) {
39 1
    $this->token = $token;
40 1
  }
41
  
42
  /**
43
   * Get current token Line Notify
44
   * 
45
   * @return string the token of Line notify
46
   */
47 2
  public function getToken() {
48 2
    return $this->token;
49
  }
50
  
51
  /**
52
   * Send text message, image or sticker on Line notify
53
   * 
54
   * @param string $text text message on Line notify can not be empty
55
   * @param string $imagePath image path you want to send on the local machine
56
   * @param array() $sticker array of line sticker ['stickerPackageId' => PACKAGE_ID, 'stickerId' => STICKER_ID ] 
0 ignored issues
show
The doc-type array() could not be parsed: Expected "|" or "end of type", but got "(" at position 5. (view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
57
   *                         more info https://devdocs.line.me/files/sticker_list.pdf
58
   * @return boolean success or fail on send Line notify message
59
   */
60
  public function send($text, $imagePath = null, $sticker = null) {
61
62
    if (empty($text)) {
63
      return false;
64
    }
65
66
    $request_params = [
67
      'headers' => [
68
        'Authorization' => 'Bearer ' . $this->token,
69
      ],
70
    ];
71
    
72
    //Message always required
73
    $request_params['multipart'] = [
74
      [
75
        'name' => 'message',
76
        'contents' => $text
77
      ]
78
    ];
79
    
80
    if (!empty($imagePath) && preg_match("#^https?://#", $imagePath)) {
81
      // Remote HTTP / HTTPS image
82
      $request_params['multipart'][] = [
83
        'name' => 'imageThumbnail',
84
        'contents' => $imagePath
85
      ];
86
      
87
      $request_params['multipart'][] = [
88
        'name' => 'imageFullsize',
89
        'contents' => $imagePath
90
      ];
91
      
92
    } elseif (!empty($imagePath) && file_exists($imagePath)) {
93
      // Local image
94
      $request_params['multipart'][] = [
95
        'name' => 'imageFile',
96
        'contents' => fopen($imagePath, 'r')
97
      ];
98
    }
99
100
    //https://devdocs.line.me/files/sticker_list.pdf
101
    if (!empty($sticker) 
102
      && !empty($sticker['stickerPackageId']) 
103
      && !empty($sticker['stickerId'])) {
104
      
105
      $request_params['multipart'][] = [
106
        'name' => 'stickerPackageId',
107
        'contents' => $sticker['stickerPackageId']
108
      ];
109
      
110
      $request_params['multipart'][] = [
111
        'name' => 'stickerId',
112
        'contents' => $sticker['stickerId']
113
      ];
114
      
115
    }
116
117
    $response = $this->http->request('POST', LineNotify::API_URL, $request_params);
118
119
    if ($response->getStatusCode() != 200) {
120
      return false;
121
    }
122
123
    $body = (string) $response->getBody();
124
    $json = json_decode($body, true);
125
    if (empty($json['status']) || empty($json['message'])) {
126
      return false;
127
    }
128
129
    return true;
130
  }
131
132
}
133