False positive on 'Bearer'
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 8.3k
- Forks
- 836
- Avg merge
- 5d 3h
- Merged PRs (30d)
- 1
Description
Describe the bug
We have an access token class, that wraps a token string and it's type.
class AccessToken(BaseModel):
"""
Wrapper of the access token.
"""
token: str
token_type: str
For the moment we only support Bearer type. Creating a token with a hard coded type raises hard coded password.
Test results:
>> Issue: [B106:hardcoded_password_funcarg] Possible hardcoded password: 'Bearer'
Severity: Low Confidence: Medium
CWE: CWE-259 (https://cwe.mitre.org/data/definitions/259.html)
Location: whist/server/api/user/auth.py:38:11
More Info: https://bandit.readthedocs.io/en/1.7.3/plugins/b106_hardcoded_password_funcarg.html
37 token = create_access_token(token_request)
38 return AccessToken(token=token, token_type='Bearer')
--------------------------------------------------
Code scanned:
Total lines of code: 9[25](https://github.com/Whist-Team/Whist-Server/runs/5397490348?check_suite_focus=true#step:5:25)
Total lines skipped (#nosec): 0
Total potential issues skipped due to specifically being disabled (e.g., #nosec BXXX): 0
Run metrics:
Total issues (by severity):
Undefined: 0
Low: 1
Medium: 0
High: 0
Total issues (by confidence):
Undefined: 0
Low: 0
Medium: 1
High: 0
Files skipped (0):
Reproduction steps
1. create a token from the above class with `AccessToken(token=token, token_type='Bearer')` where `token` is the actual token string.
Expected behavior
I my opinion this should not be raised as it is a token type not and a password.
Bandit version
1.7.3 (Default)
Python version
3.10 (Default)
Additional context
This has also been reproduced with Python 3.9.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the B106 hardcoded_password_funcarg check identified in the report and locate its implementation and tests in Bandit. Reproduce the AccessToken example, then verify that the Bearer token type is no longer reported while actual hardcoded passwords remain detected.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- security
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100