2017-06-08 32 views
0

私はLaravelでAPIのプロトタイプを作成しており、標準Auth-Guard APIを使用しているときにAPIトークンが大文字小文字を区別しないことに気付きました。したがって、 'CVC'や 'cvc'のようなapi_tokensは同じように扱われます。Laravel API-Auth-Guardでは大文字と小文字は区別されませんか?

これは予期された動作ですか?それはセキュリティに関して理想的ですか?あなたは60バイト文字列でさえそうだと思いませんか、それともあなたはどう思いますか?それを変える方法はありますか?

あなたの考えをありがとう! Carsten

答えて

0

これは当てはまりません。 Laravelはresolve the token in several ways firstときattempting to resolve an instance of the userそのメソッドが呼び出される

* Get the token for the current request. 
* 
* @return string 
*/ 
public function getTokenForRequest() 
{ 
    $token = $this->request->query($this->inputKey); 
    if (empty($token)) { 
     $token = $this->request->input($this->inputKey); 
    } 
    if (empty($token)) { 
     $token = $this->request->bearerToken(); 
    } 
    if (empty($token)) { 
     $token = $this->request->getPassword(); 
    } 
    return $token; 
} 

にしようとします。

/** 
* Get the currently authenticated user. 
* 
* @return \Illuminate\Contracts\Auth\Authenticatable|null 
*/ 
public function user() 
{ 
    // If we've already retrieved the user for the current request we can just 
    // return it back immediately. We do not want to fetch the user data on 
    // every call to this method because that would be tremendously slow. 
    if (! is_null($this->user)) { 
     return $this->user; 
    } 
    $user = null; 
    $token = $this->getTokenForRequest(); 
    if (! empty($token)) { 
     $user = $this->provider->retrieveByCredentials(
      [$this->storageKey => $token] 
     ); 
    } 
    return $this->user = $user; 
} 

そしてproviderこの場合には、いや、方法retrieveByCredentialsperforms a strict case-sensitive checkデータベース・工場->where()方法を使用してDatabaseUserProvider、あるのように、ここに表示されます:

public function retrieveByCredentials(array $credentials) 
{ 
    // First we will add each credential element to the query as a where clause. 
    // Then we can execute the query and, if we found a user, return it in a 
    // generic "user" object that will be utilized by the Guard instances. 
    $query = $this->conn->table($this->table); 
    foreach ($credentials as $key => $value) { 
     if (! Str::contains($key, 'password')) { 
      $query->where($key, $value); 
     } 
    } 
    // Now we are ready to execute the query to see if we have an user matching 
    // the given credentials. If not, we will just return nulls and indicate 
    // that there are no matching users for these given credential arrays. 
    $user = $query->first(); 
    return $this->getGenericUser($user); 
} 

あなたのケースは典型的ではありません。ここには私たちが関与していない他のコンポーネントがあります。

+0

よろしくお願いします。しかし、私が言ったように私は新鮮なlaravelのインストールで開発しています。私のdev-macであることを除いて特別なことはありません。 迷惑メールのインストールで自分のスクリプトをチェックして、自分のmacが根本的な問題であるかどうかを確認します。 ご回答ありがとうございます。 –

関連する問題