diff --git a/flask_jwt_extended/config.py b/flask_jwt_extended/config.py index 7d25651..05cc98c 100644 --- a/flask_jwt_extended/config.py +++ b/flask_jwt_extended/config.py @@ -222,9 +222,12 @@ def algorithm(self) -> str: @property def decode_algorithms(self) -> List[str]: - algorithms = current_app.config["JWT_DECODE_ALGORITHMS"] - if not algorithms: - return [self.algorithm] + # Copy before appending. The configured list can be shared by + # reference between applications, for example when they are + # built from the same object with ``from_object``, so mutating it + # would add this application's algorithm to the algorithms every + # other application accepts. + algorithms = list(current_app.config["JWT_DECODE_ALGORITHMS"] or []) if self.algorithm not in algorithms: algorithms.append(self.algorithm) return algorithms diff --git a/tests/test_config.py b/tests/test_config.py index 1d01e30..66190e4 100644 --- a/tests/test_config.py +++ b/tests/test_config.py @@ -347,3 +347,17 @@ def test_missing_algorithm_in_decode_algorithms(app): with app.test_request_context(): assert config.decode_algorithms == ["HS512", "RS256"] + + +def test_decode_algorithms_does_not_modify_config(app): + app.config["JWT_ALGORITHM"] = "RS256" + app.config["JWT_DECODE_ALGORITHMS"] = ["HS512"] + + with app.test_request_context(): + assert config.decode_algorithms == ["HS512", "RS256"] + + # The configured list must be left alone. Applications built from + # the same object share it by reference, so modifying it here would + # silently widen the algorithms the other applications accept. + assert app.config["JWT_DECODE_ALGORITHMS"] == ["HS512"] + assert config.decode_algorithms == ["HS512", "RS256"]