Skip to content

Fix propagating headers across different class instances #179

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

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

Conversation

Keisim
Copy link

@Keisim Keisim commented Jun 14, 2025

There was a bug in login function of RestClientBase which incorrectly propagated headers across all instances of the class. Fix it.

The empty dictionary was created only once in the parameter list, and then reused for all following instances.

The bug appears e.g. when trying to change the authorization method in the same service using redfish library:

  1. creating redfish_client with basic authorization adds a header
    to a global headers dictionary ('Authorization')
  2. creating a totally separate instance of redfish_client with
    session fails, because we get unexpected 'Authorization'
    header which was created in previous instance and propagated
    incorrectly

Simplified example to explain the incorrect use of dictionary parameter:

class Example:
    def bad_param(self, optional_dict={}):
        if not optional_dict:
            print('Optional dict is empty, adding something')
            optional_dict['some'] = 'thing'
        else:
            print(f'Optional dict is NOT empty: {optional_dict}')

example1 = Example()
example1.bad_param()
example2 = Example()
example2.bad_param()

Signed-off-by: Michał Michalik michal.michalik.priv@gmail.com

There was a bug in login function of RestClientBase which incorrectly
propagated headers across all instances of the class. Fix it.

The empty dictionary was created only once in the parameter list, and
then reused for all following instances.

The bug appears e.g. when trying to change the authorization method
in the same service using redfish library:
  1) creating redfish_client with basic authorization adds a header
     to a global headers dictionary ('Authorization')
  2) creating a totally separate instance of redfish_client with
     session fails, because we get unexpected 'Authorization'
     header which was created in previous instance and propagated
     incorrectly

Simplified example to explain the incorrect use of dictionary parameter:
```
class Example:
    def bad_param(self, optional_dict={}):
        if not optional_dict:
            print('Optional dict is empty, adding something')
            optional_dict['some'] = 'thing'
        else:
            print(f'Optional dict is NOT empty: {optional_dict}')

example1 = Example()
example1.bad_param()
example2 = Example()
example2.bad_param()
```

Signed-off-by: Michał Michalik <michal.michalik.priv@gmail.com>
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