Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: ChainCallback sharing default mutable list #1146

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

brendongo
Copy link

@brendongo brendongo commented Mar 6, 2020

Hello,
I am a security engineer at r2c.dev. We are working to write code
checks for security in open source code.

In python, the default values of function parameters are instantiated
at function definition time. All calls to that function that use the
default value all point to the same global object. e.g.:

def func(x=[]):
   x.append(1)
   print(x)

func() # [1]
func() # [1 , 1]

Because of this ChainCallback class potentially all share the same
list of callbacks.

Fix:
The recommended solution is to either set default to None and assign
a new empty object when the variable is None.

We have a tool called Bento you can use for your project that continuously detects problems like this one. The check that identified this will be available in the very near future.
Thanks, and I hope this helps! Let me know if you have any questions.

In python, the default values of function parameters are instantiated
at function definition time. All calls to that function that use the
default value all point to the same global object. e.g.:

```
def func(x=[]):
   x.append(1)
   print(x)

func() # [1]
func() # [1 , 1]
```

Because of this ChainCallback class potentially all share the same
list of callbacks.

Fix:
The recommended solution is to either set default to None and assign
a new empty object when the variable is None.
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.

None yet

1 participant