Skip to content

Commit 680bbc6

Browse files
committed
include leading and trailing / in the userId regexp
Signed-off-by: Julien Veyssier <julien-nc@posteo.net>
1 parent 1b25c5c commit 680bbc6

2 files changed

Lines changed: 12 additions & 5 deletions

File tree

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff 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

104104
This regular expression may or may not contain parenthesis. If it does, only the selected block will be extracted.
105105
Examples:
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'`

lib/Service/SettingsService.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff 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
}

0 commit comments

Comments
 (0)