Skip to content

Commit

Permalink
fix aud validation (#63)
Browse files Browse the repository at this point in the history
Co-authored-by: Roberto Falk <roberto.falk@sap.com>
  • Loading branch information
robertofalk and robertofalk committed Jul 18, 2023
1 parent 77c8216 commit d90c9e0
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 17 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ ENV/

# IDE
.vscode/
.devcontainer/

# local tests
local_tests/
Expand Down
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,13 @@ This project adheres to [Semantic Versioning](http://semver.org/).

The format is based on [Keep a Changelog](http://keepachangelog.com/).

## 4.0.1
### Fixed
- Bug: fix `aud` validation for IAS tokens

## 4.0.0
### Removed
- Removed suport for sap_py_jwt.
- Removed suport for sap_py_jwt

## 3.3.0
### Added
Expand Down
12 changes: 0 additions & 12 deletions Dockerfile

This file was deleted.

4 changes: 2 additions & 2 deletions sap/xssec/jwt_audience_validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def configure_trusted_clientId(self, client_id):
if client_id:
self.trusted_clientids.add(client_id)

def validate_token(self, clientId_from_token=None, audiences_from_token= [], scopes_from_token = []):
def validate_token(self, clientId_from_token=None, audiences_from_token=[], scopes_from_token=[]):
self.is_foreign_mode = False
allowed_audiences = self.extract_audiences_from_token(audiences_from_token, scopes_from_token, clientId_from_token)
if (self.validate_same_clientId(clientId_from_token) == True or
Expand All @@ -57,7 +57,7 @@ def validate_token(self, clientId_from_token=None, audiences_from_token= [], sco
return False


def extract_audiences_from_token(self, audiences_from_token= [], scopes_from_token= [], clientid_from_token=None):
def extract_audiences_from_token(self, audiences_from_token=[], scopes_from_token=[], clientid_from_token=None):
'''
Extracts Audience From Token
'''
Expand Down
6 changes: 5 additions & 1 deletion sap/xssec/security_context_ias.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,11 @@ def validate_audience(self):
"""
check `aud` in jwt token
"""
validation_result = self.audience_validator.validate_token(audiences_from_token=self.token_payload["aud"])

# Make sure `aud` is a list
aud = [self.token_payload["aud"]] if isinstance(self.token_payload["aud"], str) else self.token_payload["aud"]

validation_result = self.audience_validator.validate_token(audiences_from_token=aud)
if validation_result is False:
raise RuntimeError('Audience Validation Failed')
return self
Expand Down
2 changes: 1 addition & 1 deletion version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
4.0.0
4.0.1

0 comments on commit d90c9e0

Please sign in to comment.