79415352

Date: 2025-02-05 15:56:10
Score: 0.5
Natty:
Report link

I am unclear whether I needed to implement the prior 'solutions' but the (last?) solution to this was to manually set the PHPSESSID cookie as follows.

Cypress framework > api-utilities.ts

  1. Add the following variable outside of the class.
const configuration = {
    headers: {
        'Content-Type': 'application/json',
        Cookie: ''
    }
}
  1. Add a then to the logIn method in the class to set the cookie in the configuration variable.
await this.callApi('https://localhost/xyz/php/apis/users.php', ApiCallMethods.POST, {
    action: 'log_in',
    username: 'censored',
    password: 'censored'
}).then(response => {
    const phpSessionId = response.headers['set-cookie'][0].match(new RegExp(/(PHPSESSID=[^;]+)/))
    configuration.headers.Cookie = phpSessionId[1]
})
  1. Pass the configuration variable in the callApi method.

axios.post(url, data, configuration)

Success:

Logging in...
Sent headers: Object [AxiosHeaders] {
  Accept: 'application/json, text/plain, */*',
  'Content-Type': 'application/json',
  Cookie: ''
}
Received headers:
set-cookie: PHPSESSID=e7ik1oqt7f5j48sn0lonoh5slb; expires=Wed, 05 Feb 2025 16:47:27 GMT; Max-Age=3600;
Data:
{
  ResponseType: 'redirect',
  URL: 'http://localhost/xyz/php/pages/games.php',
  'logged in:': true
}

Subsequent API call...
Sent headers: Object [AxiosHeaders] {
  Accept: 'application/json, text/plain, */*',    
  'Content-Type': 'application/json',
  Cookie: 'PHPSESSID=e7ik1oqt7f5j48sn0lonoh5slb'  
}
Received headers:
**{no PHPSESSID because its using the one acquired by the logIn method}**
Data:
{"PHP > logged in?":true}
{"ResponseType":"redirect","URL":"http:\/\/localhost\/xyz\/php\/pages\/games.php","Id":"64"}
Reasons:
  • Blacklisted phrase (0.5): I need
  • Long answer (-1):
  • Has code block (-0.5):
  • Contains question mark (0.5):
  • Self-answer (0.5):
  • Low reputation (0.5):
Posted by: Zuno