File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -97,17 +97,17 @@ you can configure user_oidc to apply a regular expression to extract the user ID
9797
9898``` php
9999'user_oidc' => [
100- 'user_id_regexp' => 'u=([^,]+)'
100+ 'user_id_regexp' => '/ u=([^,]+)/ '
101101]
102102```
103103
104104This regular expression may or may not contain parenthesis. If it does, only the selected block will be extracted.
105105Examples:
106106
107- * ` '[a-zA-Z]+' `
107+ * ` '/ [a-zA-Z]+/ ' `
108108 * ` '123-abc-123' ` will give ` 'abc' `
109109 * ` '123-abc-345-def' ` will give ` 'abc' `
110- * ` 'u=([^,]+)' `
110+ * ` '/ u=([^,]+)/ ' `
111111 * ` 'u=123' ` will give ` '123' `
112112 * ` 'anything,u=123,anything' ` will give ` '123' `
113113 * ` 'anything,u=123,anything,u=345' ` will give ` '123' `
Original file line number Diff line number Diff line change @@ -46,8 +46,15 @@ public function setAllowMultipleUserBackEnds(bool $value): void {
4646
4747 public function parseUserId (string $ userId ): string {
4848 $ oidcSystemConfig = $ this ->config ->getSystemValue ('user_oidc ' , []);
49- if (isset ($ oidcSystemConfig ['user_id_regexp ' ]) && $ oidcSystemConfig ['user_id_regexp ' ] !== '' ) {
50- if (preg_match ('/ ' . $ oidcSystemConfig ['user_id_regexp ' ] . '/ ' , $ userId , $ matches ) === 1 ) {
49+ if (isset ($ oidcSystemConfig ['user_id_regexp ' ]) && is_string ($ oidcSystemConfig ['user_id_regexp ' ]) && $ oidcSystemConfig ['user_id_regexp ' ] !== '' ) {
50+ // check that the regexp is valid
51+ if (preg_match ('/^\/.+\/[a-z]*$/ ' , $ oidcSystemConfig ['user_id_regexp ' ], $ matches ) === 1 ) {
52+ $ this ->logger ->warning (
53+ 'Incorrect "user_id_regexp", it should start and end with a "/" and have optional trailing modifiers ' ,
54+ ['regexp ' => $ oidcSystemConfig ['user_id_regexp ' ]],
55+ );
56+ }
57+ if (preg_match ($ oidcSystemConfig ['user_id_regexp ' ], $ userId , $ matches ) === 1 ) {
5158 return $ matches [1 ] ?? $ matches [0 ];
5259 }
5360 }
You can’t perform that action at this time.
0 commit comments