Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions flask_jwt_extended/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 14 additions & 0 deletions tests/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]