Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unable to read certain cookies

i am trying to read cookies from browser in order to setup an authguard. I am trying to check if cookies are setup then user is logged in otherwise not. For this purpose i am using ngx-cookie-service. Here is code for getting value from cookies.

import {UserAuthService} from '../services';
import { CookieService } from 'ngx-cookie-service';

@Injectable()
export class AuthService {

constructor(
  private cookieService: CookieService,
}

  getSessionid() {
    this.cookieService.set('test', '123');
    console.log(this.cookieService.get('test'));
    console.log(this.cookieService.get('sessionid'));
    console.log(this.cookieService.get('csrftoken'));
    console.log(this.cookieService.get('messages'));
    return this.cookieService.get('sessionid') || null;
  } 
}

In above code it is printing certain values correctly in console such as test and csrftoken but messages and sessionid is blank where as in application tab i can see all the cookies. Here is a screenshot my application tab. enter image description here

and here is screenshot my console enter image description here

Anybody having idea what's wrong here?

like image 635
Shoaib Iqbal Avatar asked Jun 26 '18 14:06

Shoaib Iqbal


1 Answers

In case you never found the answer -

That's because the cookies that are not printing are 'httpOnly'. You would a tick against those cookies on the 7th column of your first screenshot.

https://owasp.org/www-community/HttpOnly

like image 126
Dibzmania Avatar answered Dec 30 '22 00:12

Dibzmania