Commit 02ccacb
Fail closed on mTLS PoP token_type downgrade; honor verify; lock session build
Harden the mTLS Proof-of-Possession path with three fixes surfaced by review.
Fail closed on a token_type downgrade. A cert-bound request is driven by our
request flag, not the response, so if ESTS answers an mtls_pop request with a
non-cert-bound token we previously still attached binding_certificate and cached
it as bound. Now acquire_token_for_client returns token_type_mismatch when the
response token_type is not "mtls_pop", and _MtlsClient only re-injects key_id
(the cache binding) when the response is actually mtls_pop. A downgraded token
therefore caches as an ordinary token that the cert-bound silent query can never
match, so the flow re-fetches and fails closed every time. Mirrors MSAL .NET/Go.
Honor verify in the mTLS transport. A custom ssl_context bypasses requests' own
verify handling, so verify was silently ignored: verify=False raised a cryptic
ValueError and the default used the system store instead of certifi. The context
builder now matches requests' semantics (certifi default, CA file/dir path, or
disabled) so verify behaves as documented.
Serialize first session build. Wrap the lazy session construction in a
double-checked lock so a cold-start burst on a multi-threaded confidential
client no longer builds N transports (each writing the private key to a temp
file) and orphans all but one.
Also drop stray blank lines that had crept into the acquire_token_for_client
mTLS setup block.
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>1 parent 224a003 commit 02ccacb
3 files changed
Lines changed: 88 additions & 38 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
300 | 300 | | |
301 | 301 | | |
302 | 302 | | |
303 | | - | |
304 | | - | |
305 | | - | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
306 | 312 | | |
307 | 313 | | |
308 | 314 | | |
| |||
2799 | 2805 | | |
2800 | 2806 | | |
2801 | 2807 | | |
2802 | | - | |
2803 | 2808 | | |
2804 | | - | |
2805 | 2809 | | |
2806 | | - | |
2807 | 2810 | | |
2808 | | - | |
2809 | 2811 | | |
2810 | | - | |
2811 | 2812 | | |
2812 | | - | |
2813 | 2813 | | |
2814 | | - | |
2815 | 2814 | | |
2816 | | - | |
2817 | 2815 | | |
2818 | | - | |
2819 | 2816 | | |
2820 | | - | |
2821 | 2817 | | |
2822 | | - | |
2823 | 2818 | | |
2824 | | - | |
2825 | 2819 | | |
2826 | | - | |
2827 | 2820 | | |
2828 | | - | |
2829 | 2821 | | |
2830 | | - | |
2831 | 2822 | | |
2832 | | - | |
2833 | 2823 | | |
2834 | | - | |
2835 | 2824 | | |
2836 | | - | |
2837 | 2825 | | |
2838 | | - | |
2839 | 2826 | | |
2840 | | - | |
2841 | 2827 | | |
2842 | | - | |
2843 | 2828 | | |
2844 | | - | |
2845 | 2829 | | |
2846 | | - | |
2847 | 2830 | | |
2848 | 2831 | | |
2849 | 2832 | | |
2850 | 2833 | | |
2851 | 2834 | | |
| 2835 | + | |
| 2836 | + | |
| 2837 | + | |
| 2838 | + | |
| 2839 | + | |
| 2840 | + | |
| 2841 | + | |
| 2842 | + | |
| 2843 | + | |
| 2844 | + | |
| 2845 | + | |
| 2846 | + | |
| 2847 | + | |
| 2848 | + | |
2852 | 2849 | | |
2853 | 2850 | | |
2854 | 2851 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
| 15 | + | |
15 | 16 | | |
16 | 17 | | |
17 | 18 | | |
| |||
116 | 117 | | |
117 | 118 | | |
118 | 119 | | |
| 120 | + | |
119 | 121 | | |
120 | 122 | | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
121 | 127 | | |
122 | | - | |
123 | | - | |
124 | | - | |
125 | | - | |
126 | | - | |
127 | | - | |
128 | | - | |
129 | | - | |
130 | | - | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
131 | 139 | | |
132 | 140 | | |
133 | 141 | | |
| |||
166 | 174 | | |
167 | 175 | | |
168 | 176 | | |
169 | | - | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
170 | 204 | | |
171 | 205 | | |
172 | 206 | | |
173 | 207 | | |
174 | 208 | | |
175 | 209 | | |
176 | 210 | | |
177 | | - | |
178 | 211 | | |
179 | 212 | | |
180 | | - | |
| 213 | + | |
181 | 214 | | |
182 | 215 | | |
183 | 216 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1670 | 1670 | | |
1671 | 1671 | | |
1672 | 1672 | | |
| 1673 | + | |
| 1674 | + | |
| 1675 | + | |
| 1676 | + | |
| 1677 | + | |
| 1678 | + | |
| 1679 | + | |
| 1680 | + | |
| 1681 | + | |
| 1682 | + | |
| 1683 | + | |
| 1684 | + | |
| 1685 | + | |
| 1686 | + | |
| 1687 | + | |
| 1688 | + | |
| 1689 | + | |
| 1690 | + | |
| 1691 | + | |
| 1692 | + | |
1673 | 1693 | | |
1674 | 1694 | | |
1675 | 1695 | | |
| |||
0 commit comments