PyCQA / PyCQA/bandit

False positive on 'Bearer'

Open
#842 0 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

bug
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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.