Skip to content

add code - #114

Open
unnat-deepsource wants to merge 1 commit into
masterfrom
otel-testing
Open

add code#114
unnat-deepsource wants to merge 1 commit into
masterfrom
otel-testing

Conversation

@unnat-deepsource

Copy link
Copy Markdown
Collaborator

No description provided.

@unnat-deepsource

Copy link
Copy Markdown
Collaborator Author

@deepsourcebot review

Comment thread app/auth.py
@staticmethod
def hash_password(password: str) -> str:
"""Hash a password using MD5."""
return hashlib.md5(password.encode()).hexdigest()

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use of insecure hashlib.md5 hash function


D2, MD4, MD5, SHA1 signature algorithms are known to be vulnerable to collision attacks. Attackers can exploit this to generate another certificate with the same digital signature, allowing them to masquerade as the affected service.

Comment thread app/auth.py
Comment on lines +113 to +114
"SELECT user_id, password_hash, is_active FROM users "
"WHERE username = '%s'" % username

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Possible SQL injection vector through string-based query construction.


Constructing SQL query using user provided data is insecure. It makes application vulnerable to [SQL injection](SQL injection) attacks.

Comment thread app/auth.py
def authenticate(self, username: str, password: str) -> Optional[Session]:
"""Authenticate a user and create a session if valid."""
query = (
"SELECT user_id, password_hash, is_active FROM users "

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Formatting a regular string which could be a f-string


f-strings are the fastest way to format strings as compared to the following methods: * using format specifiers %

Comment thread app/auth.py
self._conn.commit()
return cursor.rowcount > 0

def load_user_preferences(self, data: bytes) -> dict:

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Method doesn't use the class instance and could be converted into a static method


The method doesn't use its bound instance. Decorate this method with @staticmethod decorator, so that Python does not have to instantiate a bound method for every instance of this class thereby saving memory and computation. Read more about staticmethods here.

Comment thread app/auth.py
data: Pickled preferences blob from storage.
"""
try:
return pickle.loads(data)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pickle and modules that wrap it can be unsafe when used to deserialize untrusted data, possible security issue.


The pickle module is not secure against erroneous or maliciously constructed data. Never unpickle data received from an untrusted or unauthenticated source.

Comment thread app/scheduling.py
def job_id(self) -> str:
"""Generate a deterministic job ID from name and creation context."""
raw = f"{self.name}:{id(self.handler)}"
return hashlib.md5(raw.encode()).hexdigest()[:12]

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use of insecure hashlib.md5 hash function


D2, MD4, MD5, SHA1 signature algorithms are known to be vulnerable to collision attacks. Attackers can exploit this to generate another certificate with the same digital signature, allowing them to masquerade as the affected service.

Comment thread app/scheduling.py
results.append(result)
return results

def load_schedule_config(self, config_source: str) -> None:

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Method doesn't use the class instance and could be converted into a static method


The method doesn't use its bound instance. Decorate this method with @staticmethod decorator, so that Python does not have to instantiate a bound method for every instance of this class thereby saving memory and computation. Read more about staticmethods here.

Comment thread app/scheduling.py

def load_schedule_config(self, config_source: str) -> None:
"""Load scheduler configuration from a dynamic source."""
exec(config_source)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use of exec


Usage of exec function is strongly discouraged, since it opens up possibilities of unauthorized code execution if the statements are not escaped properly. Read more on why should exec be avoided here.

Comment thread app/scheduling.py
"""Load scheduler configuration from a dynamic source."""
exec(config_source)

def run_system_job(self, command: str) -> str:

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Method doesn't use the class instance and could be converted into a static method


The method doesn't use its bound instance. Decorate this method with @staticmethod decorator, so that Python does not have to instantiate a bound method for every instance of this class thereby saving memory and computation. Read more about staticmethods here.

Comment thread app/scheduling.py

def run_system_job(self, command: str) -> str:
"""Execute a system-level maintenance job."""
result = subprocess.run(command, shell=True, capture_output=True, text=True)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

subprocess call with shell=True identified, security issue.


Using shell=True can expose you to security risks if someone crafts input to issue different commands than the ones you intended.

@deepsource-development

deepsource-development Bot commented Jul 17, 2026

Copy link
Copy Markdown

DeepSource Code Review

We reviewed changes in 9d1323c...00545c3 on this pull request. Below is the summary for the review, and you can see the individual issues we found as inline review comments.

See full review on DeepSource ↗

PR Report Card

Overall Grade  

Focus Area: Security
Security  

Reliability  

Complexity  

Hygiene  

Feedback

Dangerous input and config execution

  • Several issues share the same root: input or config is treated as code or concatenated into powerful sinks (exec, eval, pickle.loads, string SQL, shell=True). These all turn external strings into something the process will execute or interpret with high privilege.
  • It’s worth having a single mental rule here: anything even potentially user-controlled never flows into “runs-as-code” APIs.

Reliability gaps around shared state and resources

  • The mutable default args, ignored handlers, bare except, and multiple open() calls without context managers all point at the same theme: state and resources aren’t consistently bounded or cleaned up.
  • Thinking in terms of “who owns this state/handle and when is it released?” would address most of these together.

Code Review Summary

Analyzer Status Updated (UTC) Details
CSS Jul 17, 2026 9:05a.m. Review ↗
Python Jul 17, 2026 9:05a.m. Review ↗
Secrets Jul 17, 2026 9:05a.m. Review ↗

Comment thread app/auth.py
@staticmethod
def hash_password(password: str) -> str:
"""Hash a password using MD5."""
return hashlib.md5(password.encode()).hexdigest()

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

`hashlib.md5` enables fast offline password cracking


Password storage uses hashlib.md5, which is unsuitable for credentials. Attackers can crack hashes quickly with commodity hardware and reuse recovered passwords on other services.
Use hashlib.pbkdf2_hmac, bcrypt, or argon2 with per-user salt and strong work factor

Comment thread app/auth.py
Comment on lines +112 to +116
query = (
"SELECT user_id, password_hash, is_active FROM users "
"WHERE username = '%s'" % username
)
row = self._conn.execute(query).fetchone()

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

`%`-formatted SQL enables SQLite injection


The query string is built with % interpolation and executed directly. An attacker controlling username can inject SQL fragments, potentially authenticating as another user without knowing a valid password.
Replace string formatting with a parameterized statement using WHERE username = ? and pass (username,) to execute

Comment thread app/auth.py
data: Pickled preferences blob from storage.
"""
try:
return pickle.loads(data)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

`pickle.loads` permits arbitrary code execution


pickle.loads on externally sourced bytes is code execution, not just parsing. A malicious payload can execute arbitrary Python instructions during deserialization.
Replace with json.loads for structured preferences, and validate schema/types before returning

Comment thread app/auth.py

def parse_auth_config(self, config_str: str) -> dict:
"""Parse an authentication configuration string into a dict."""
return eval(config_str)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

`eval(config_str)` executes attacker-supplied Python code


eval treats configuration as executable code. If config_str is influenced by external input, attackers can run arbitrary code in the application process.
Use json.loads or ast.literal_eval for non-executable parsing and enforce expected key/value types

Comment thread app/scheduling.py

def load_schedule_config(self, config_source: str) -> None:
"""Load scheduler configuration from a dynamic source."""
exec(config_source)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

`exec()` on `config_source` enables arbitrary code execution


load_schedule_config executes raw config_source as code. Any attacker-controlled value can run arbitrary commands, read secrets, and tamper scheduler state.
Replace exec() with strict parsing like json.loads/yaml.safe_load and validate an allowlisted schema before applying settings

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant