Skip to content

Commit f733b10

Browse files
committed
Do not crash when entity-selection-profile attribute has invalid JSON
1 parent 7ae32b3 commit f733b10

File tree

2 files changed

+127
-4
lines changed

2 files changed

+127
-4
lines changed

src/pyff/samlmd.py

+15-4
Original file line numberDiff line numberDiff line change
@@ -1047,14 +1047,25 @@ def discojson_sp_attr(e):
10471047
if b64_trustinfos is None:
10481048
return None
10491049

1050+
entityID = e.get('entityID', None)
1051+
if entityID is None:
1052+
return None
1053+
10501054
sp = {}
1051-
sp['entityID'] = e.get('entityID', None)
1055+
sp['entityID'] = entityID
10521056
sp['profiles'] = {}
10531057

10541058
for b64_trustinfo in b64_trustinfos:
1055-
str_trustinfo = b64decode(b64_trustinfo.encode('ascii'))
1056-
trustinfo = json.loads(str_trustinfo.decode('utf8'))
1057-
sp['profiles'].update(trustinfo['profiles'])
1059+
try:
1060+
str_trustinfo = b64decode(b64_trustinfo.encode('ascii'))
1061+
trustinfo = json.loads(str_trustinfo.decode('utf8'))
1062+
sp['profiles'].update(trustinfo['profiles'])
1063+
1064+
except Exception as e:
1065+
log.warning(f"Invalid entity-selection-profile attribute for {entityID}: {e}")
1066+
1067+
if not sp['profiles']:
1068+
return None
10581069

10591070
return sp
10601071

src/pyff/test/data/metadata/test-sp-trustinfo-in-attr.xml

+112
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,118 @@ fMou5aW0mZ+QgJNKOrxY5vFxUq6pn3OiYbBu3m1C9ajbU/nx2evzt4+qUwTfHFb+
7171
ZgXpOtmxRekFzVvGZ18BSPJKwAAqqZ11X7skT/NwEAhbgplVPv9WkDmDzqNvHqQJ
7272
nyRgD2ZqUPU9nEOjGy0gI07dciVcYZQ+CiZeSECIWgQwjDEBDuwMCVAZA6gfdz6C
7373
KJuN+RUSKPEcxPxle1MiB4MU0ei5X4xUbvLWKn9Ok7TOXg2BpnMAv6eON1wVo0Aa
74+
D265cqy6Le/toVg=</ds:X509Certificate>
75+
</ds:X509Data>
76+
</ds:KeyInfo>
77+
<md:EncryptionMethod Algorithm="http://www.w3.org/2009/xmlenc11#aes128-gcm"/>
78+
<md:EncryptionMethod Algorithm="http://www.w3.org/2009/xmlenc11#aes192-gcm"/>
79+
<md:EncryptionMethod Algorithm="http://www.w3.org/2009/xmlenc11#aes256-gcm"/>
80+
<md:EncryptionMethod Algorithm="http://www.w3.org/2001/04/xmlenc#aes128-cbc"/>
81+
<md:EncryptionMethod Algorithm="http://www.w3.org/2001/04/xmlenc#aes192-cbc"/>
82+
<md:EncryptionMethod Algorithm="http://www.w3.org/2001/04/xmlenc#aes256-cbc"/>
83+
<md:EncryptionMethod Algorithm="http://www.w3.org/2001/04/xmlenc#tripledes-cbc"/>
84+
<md:EncryptionMethod Algorithm="http://www.w3.org/2009/xmlenc11#rsa-oaep"/>
85+
<md:EncryptionMethod Algorithm="http://www.w3.org/2001/04/xmlenc#rsa-oaep-mgf1p"/>
86+
</md:KeyDescriptor>
87+
<md:AssertionConsumerService Binding="urn:oasis:names:tc:SAML:2.0:bindings:HTTP-POST" Location="https://cpauth.icos-cp.eu/saml/SAML2/POST" index="1" isDefault="true"/>
88+
<md:AttributeConsumingService index="1">
89+
<md:ServiceName xml:lang="en">ICOS Carbon Portal SAML service</md:ServiceName>
90+
<md:ServiceName xml:lang="sv">ICOS Kolportalens SAML tjänst</md:ServiceName>
91+
<md:RequestedAttribute FriendlyName="givenName" Name="urn:oid:2.5.4.42" NameFormat="urn:oasis:names:tc:SAML:2.0:attrname-format:uri" isRequired="true"/>
92+
<md:RequestedAttribute FriendlyName="sn" Name="urn:oid:2.5.4.4" NameFormat="urn:oasis:names:tc:SAML:2.0:attrname-format:uri" isRequired="true"/>
93+
<md:RequestedAttribute FriendlyName="mail" Name="urn:oid:0.9.2342.19200300.100.1.3" NameFormat="urn:oasis:names:tc:SAML:2.0:attrname-format:uri" isRequired="true"/>
94+
</md:AttributeConsumingService>
95+
</md:SPSSODescriptor>
96+
<md:Organization>
97+
<md:OrganizationName xml:lang="en">ICOS Carbon Portal</md:OrganizationName>
98+
<md:OrganizationName xml:lang="sv">ICOS Kolportalen</md:OrganizationName>
99+
<md:OrganizationDisplayName xml:lang="en">Carbon Portal</md:OrganizationDisplayName>
100+
<md:OrganizationDisplayName xml:lang="sv">Kolportalen</md:OrganizationDisplayName>
101+
<md:OrganizationURL xml:lang="en">https://www.icos-cp.eu/</md:OrganizationURL>
102+
<md:OrganizationURL xml:lang="sv">https://www.icos-cp.eu/</md:OrganizationURL>
103+
</md:Organization>
104+
<md:ContactPerson contactType="technical">
105+
<md:GivenName>Oleg</md:GivenName>
106+
<md:SurName>Mirzov</md:SurName>
107+
<md:EmailAddress>mailto:[email protected]</md:EmailAddress>
108+
</md:ContactPerson>
109+
<md:ContactPerson contactType="administrative">
110+
<md:GivenName>Alex</md:GivenName>
111+
<md:SurName>Vermeulen</md:SurName>
112+
<md:EmailAddress>mailto:[email protected]</md:EmailAddress>
113+
</md:ContactPerson>
114+
</md:EntityDescriptor>
115+
<md:EntityDescriptor entityID="https://example.org/shibboleth">
116+
<md:Extensions>
117+
<mdrpi:RegistrationInfo registrationAuthority="http://www.swamid.se/" registrationInstant="2015-02-11T11:09:51Z">
118+
<mdrpi:RegistrationPolicy xml:lang="en">http://swamid.se/policy/mdrps</mdrpi:RegistrationPolicy>
119+
</mdrpi:RegistrationInfo>
120+
<alg:DigestMethod Algorithm="http://www.w3.org/2001/04/xmlenc#sha512"/>
121+
<alg:DigestMethod Algorithm="http://www.w3.org/2001/04/xmldsig-more#sha384"/>
122+
<alg:DigestMethod Algorithm="http://www.w3.org/2001/04/xmlenc#sha256"/>
123+
<alg:DigestMethod Algorithm="http://www.w3.org/2001/04/xmldsig-more#sha224"/>
124+
<alg:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1"/>
125+
<alg:SigningMethod Algorithm="http://www.w3.org/2001/04/xmldsig-more#ecdsa-sha512"/>
126+
<alg:SigningMethod Algorithm="http://www.w3.org/2001/04/xmldsig-more#ecdsa-sha384"/>
127+
<alg:SigningMethod Algorithm="http://www.w3.org/2001/04/xmldsig-more#ecdsa-sha256"/>
128+
<alg:SigningMethod Algorithm="http://www.w3.org/2001/04/xmldsig-more#ecdsa-sha224"/>
129+
<alg:SigningMethod Algorithm="http://www.w3.org/2001/04/xmldsig-more#rsa-sha512"/>
130+
<alg:SigningMethod Algorithm="http://www.w3.org/2001/04/xmldsig-more#rsa-sha384"/>
131+
<alg:SigningMethod Algorithm="http://www.w3.org/2001/04/xmldsig-more#rsa-sha256"/>
132+
<alg:SigningMethod Algorithm="http://www.w3.org/2009/xmldsig11#dsa-sha256"/>
133+
<alg:SigningMethod Algorithm="http://www.w3.org/2001/04/xmldsig-more#ecdsa-sha1"/>
134+
<alg:SigningMethod Algorithm="http://www.w3.org/2000/09/xmldsig#rsa-sha1"/>
135+
<alg:SigningMethod Algorithm="http://www.w3.org/2000/09/xmldsig#dsa-sha1"/>
136+
<mdattr:EntityAttributes>
137+
<saml:Attribute NameFormat="urn:oasis:names:tc:SAML:2.0:attrname-format:uri" Name="http://macedir.org/entity-category">
138+
<saml:AttributeValue>http://www.geant.net/uri/dataprotection-code-of-conduct/v1</saml:AttributeValue>
139+
</saml:Attribute>
140+
<saml:Attribute NameFormat="urn:oasis:names:tc:SAML:2.0:attrname-format:uri" Name="https://refeds.org/entity-selection-profile">
141+
<saml:AttributeValue>invalidValueForAttribute</saml:AttributeValue>
142+
</saml:Attribute>
143+
</mdattr:EntityAttributes>
144+
</md:Extensions>
145+
<md:SPSSODescriptor protocolSupportEnumeration="urn:oasis:names:tc:SAML:2.0:protocol">
146+
<md:Extensions>
147+
<init:RequestInitiator Binding="urn:oasis:names:tc:SAML:profiles:SSO:request-init" Location="https://cpauth.icos-cp.eu/saml/login"/>
148+
<mdui:UIInfo>
149+
<mdui:DisplayName xml:lang="en">Carbon Portal authentication service</mdui:DisplayName>
150+
<mdui:DisplayName xml:lang="sv">Kolportalens autentiseringstjänst</mdui:DisplayName>
151+
<mdui:Description xml:lang="en">Single Sign On for services of ICOS Carbon Portal. Maintained by the Carbon Portal team at Physical Geography department (nateko.lu.se).</mdui:Description>
152+
<mdui:Description xml:lang="sv">Single Sign On tjänst för ICOS Kolportalen. Hanteras av Carbon Portal teamet på INES (nateko.lu.se).</mdui:Description>
153+
<mdui:PrivacyStatementURL xml:lang="en">https://cpauth.icos-cp.eu/saml/privacyStatement</mdui:PrivacyStatementURL>
154+
<mdui:InformationURL xml:lang="en">https://www.icos-cp.eu/</mdui:InformationURL>
155+
<mdui:InformationURL xml:lang="sv">https://www.icos-cp.eu/</mdui:InformationURL>
156+
<mdui:PrivacyStatementURL xml:lang="sv">https://cpauth.icos-cp.eu/saml/privacyStatement</mdui:PrivacyStatementURL>
157+
</mdui:UIInfo>
158+
</md:Extensions>
159+
<md:KeyDescriptor>
160+
<ds:KeyInfo>
161+
<ds:KeyName>cpauth.icos-cp.eu</ds:KeyName>
162+
<ds:X509Data>
163+
<ds:X509SubjectName>CN=cpauth.icos-cp.eu</ds:X509SubjectName>
164+
<ds:X509Certificate>MIIEJzCCAw+gAwIBAgIJANC3VWNs7fbTMA0GCSqGSIb3DQEBCwUAMIGpMQswCQYD
165+
VQQGEwJTRTERMA8GA1UECAwIU2vDg8KlbmUxDTALBgNVBAcMBEx1bmQxGzAZBgNV
166+
BAoMEklDT1MgQ2FyYm9uIFBvcnRhbDEfMB0GA1UECwwWQXV0aGVudGljYXRpb24g
167+
U2VydmljZTEaMBgGA1UEAwwRY3BhdXRoLmljb3MtY3AuZXUxHjAcBgkqhkiG9w0B
168+
CQEWD2luZm9AaWNvcy1jcC5ldTAeFw0xNTAyMDUxMjI0MzZaFw0yNTAyMDIxMjI0
169+
MzZaMIGpMQswCQYDVQQGEwJTRTERMA8GA1UECAwIU2vDg8KlbmUxDTALBgNVBAcM
170+
BEx1bmQxGzAZBgNVBAoMEklDT1MgQ2FyYm9uIFBvcnRhbDEfMB0GA1UECwwWQXV0
171+
aGVudGljYXRpb24gU2VydmljZTEaMBgGA1UEAwwRY3BhdXRoLmljb3MtY3AuZXUx
172+
HjAcBgkqhkiG9w0BCQEWD2luZm9AaWNvcy1jcC5ldTCCASIwDQYJKoZIhvcNAQEB
173+
BQADggEPADCCAQoCggEBAM2QN1jaZJeuPAH+4sVMZKk7vg4JIbUuTMKk0+KIAg5M
174+
XiVsRiEUjY+LtIncrvA/kf2CIySI0WkbwZMjcDd03hNj4kLWhuyxfOCwDO6DsUbG
175+
MbyI6HIYWXJp5ljfEEFgtMqT3dDtD5vwq8h4Zy20ukxOoIokKczrAvn4JjkMsj6Z
176+
0CEAFBC29o4E8PWQbUBgvt6Z+2ao+RHMLD7nZVBx98Occ9KfnYnDDd9Oi1XFe009
177+
zaSbcqY2RpN8I9hcW/KQf3KnGW5xZ5dr4rhGklCkYr+h0W3xKu+hin8bk91t1Dkr
178+
gaKl/N7M3Oof3k+7ZBlwaV97es5InWCeNgDxCGkBRNsCAwEAAaNQME4wHQYDVR0O
179+
BBYEFDcD7MVudooGaNRYqXBYqQi3VzGxMB8GA1UdIwQYMBaAFDcD7MVudooGaNRY
180+
qXBYqQi3VzGxMAwGA1UdEwQFMAMBAf8wDQYJKoZIhvcNAQELBQADggEBABS02eZS
181+
weXGMJ2fEIy2JH0VhCbjuX/rz+8Hfh9LjzNb3QwKHuwP83yvPqRulV9FYmvOoK8T
182+
fMou5aW0mZ+QgJNKOrxY5vFxUq6pn3OiYbBu3m1C9ajbU/nx2evzt4+qUwTfHFb+
183+
ZgXpOtmxRekFzVvGZ18BSPJKwAAqqZ11X7skT/NwEAhbgplVPv9WkDmDzqNvHqQJ
184+
nyRgD2ZqUPU9nEOjGy0gI07dciVcYZQ+CiZeSECIWgQwjDEBDuwMCVAZA6gfdz6C
185+
KJuN+RUSKPEcxPxle1MiB4MU0ei5X4xUbvLWKn9Ok7TOXg2BpnMAv6eON1wVo0Aa
74186
D265cqy6Le/toVg=</ds:X509Certificate>
75187
</ds:X509Data>
76188
</ds:KeyInfo>

0 commit comments

Comments
 (0)