Skip to content

Commit

Permalink
fix: allow ":" character in digestAuth password (#532)
Browse files Browse the repository at this point in the history
`str.split()` -function would cut rest of the password off when
encountering a "`:`" character.


Old:
```javascript
let s = 'user:passwordwith:character';
const [user, pass] = userpass.split(':');
console.log(`User '${user}' and pass '${pass}'`);
``` 
Output: `User 'user' and pass 'passwordwith'`

Fixed:
```javascript
const user = userpass.split(':', 1);
const pass = userpass.slice(user[0].length+1);
console.log(`User '${user}' and pass '${pass}'
``` 
Output: `User 'user' and pass 'passwordwith:character'`

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit


- **Bug Fixes**
- Improved the extraction process for username and password from the
userpass string, enhancing clarity and maintainability.

- **Refactor**
- Refined the logic within the digest authentication header function for
better readability without altering its overall functionality.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->
  • Loading branch information
kulpsin authored Sep 11, 2024
1 parent 5c7d555 commit c6b6f88
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,9 @@ export function digestAuthHeader(method: string, uri: string, wwwAuthenticate: s
}

let qop = opts.qop || '';
const [ user, pass ] = userpass.split(':');
const index = userpass.indexOf(':');
const user = userpass.substring(0, index);
const pass = userpass.substring(index + 1);

let nc = String(++NC);
nc = `${NC_PAD.substring(nc.length)}${nc}`;
Expand Down

0 comments on commit c6b6f88

Please sign in to comment.