py-radius icon indicating copy to clipboard operation
py-radius copied to clipboard

Unknown attribute causes exception

Open mqgmaster opened this issue 7 years ago • 5 comments

The following lines causes an exception when a unknown attribute is received from server.

        """
        Add an item to attributes (by name or id)
        """
        try:
            code, name = self.__getkeys(key)
        except KeyError:
            raise ValueError('Invalid radius attribute: %s' % key)
        values = self.get(code, [])
        values.append(value)
        UserDict.__setitem__(self, code, values)

The correct, in my opinion, is log a warning and continue the authentication. That lib does not need to validate the attributes, this is responsibility of the application using py-radius.

        try:
            code, name = self.__getkeys(key)
            values = self.get(code, [])
            values.append(value)
            UserDict.__setitem__(self, code, values)
        except KeyError:
            LOGGER.warning('Invalid radius attribute: %s' % key)

mqgmaster avatar Apr 27 '18 17:04 mqgmaster

Good point, your solution still validates the attributes, disallowing caller from using unknown attributes.

I think if key is a code, we can warn via logger and proceed to add the attribute anyway. When key is a name, it must be known so we can look up the code.

btimby avatar May 04 '18 15:05 btimby

https://github.com/btimby/py-radius/pull/10

btimby avatar May 04 '18 16:05 btimby

Does the PR address your problem?

btimby avatar May 04 '18 16:05 btimby

Thanks @btimby. Your solution looks better.

As soon as possible I will update my code to validate the behavior.

mqgmaster avatar May 23 '18 13:05 mqgmaster

@mqgmaster Thank you sir! Please let me know.

btimby avatar May 23 '18 13:05 btimby