PyCQA / PyCQA/bandit

False negative: B103 fails to detect dangerous permissions set via stat module constants

Open
#1,390 0 comments 0 reactions 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

Rule B103 currently only evaluates the mode argument in chmod if it is an integer literal. It fails to detect dangerous file permissions when developers use standard stat module constants (e.g., stat.S_IWOTH | stat.S_IWGRP). These are parsed as AST BinOp or Attribute nodes rather than Int nodes, causing the rule to bypass them completely.

Reproduction steps

Run Bandit on the following snippet:

import os
import stat
# False Negative
os.chmod('config.ini', stat.S_IWGRP | stat.S_IWOTH)
Expected behavior

Bandit should resolve or explicitly check for dangerous stat constants (like S_IWOTH, S_IWGRP, S_IXOTH, S_IXGRP) in Attribute and BinOp nodes, raising warnings just as it does for integer literals like 0o777.

Bandit version

1.9.1 (Default)

Python version

3.14 (Default)

Additional context

No response

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 at the B103 rule implementation and run the provided Python chmod reproduction with stat.S_IWGRP | stat.S_IWOTH. Trace how mode arguments are handled for integer literals, Attribute nodes, and BinOp nodes. Done means dangerous stat constants such as S_IWOTH, S_IWGRP, S_IXOTH, and S_IXGRP produce warnings like equivalent integer literals.

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
Quiet
Clarity
Mostly clear
Newbie friendliness
68/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.