Skip to content

Commit 3bc12ce

Browse files
nox-404Aurelien Gaston
authored andcommitted
Firewall: Aliases - allow setting a custom auth http header
1 parent e996311 commit 3bc12ce

File tree

4 files changed

+20
-0
lines changed

4 files changed

+20
-0
lines changed

src/opnsense/mvc/app/models/OPNsense/Firewall/Alias.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,19 @@ public function performValidation($validateFullModel = false)
7878
$messages->appendMessage(new Message(gettext('Illegal characters in token'), $ref . '.authtype'));
7979
}
8080
break;
81+
case 'Header':
82+
if (empty($username) || empty($password)) {
83+
$messages->appendMessage(new Message(gettext('Please provide a header key and value when Header auth is selected'), $ref . '.authtype'));
84+
} elseif (strlen($username) > 255) {
85+
$messages->appendMessage(new Message(gettext('Invalid key length'), $ref . '.authtype'));
86+
} elseif (strlen($password) > 512) {
87+
$messages->appendMessage(new Message(gettext('Invalid value length'), $ref . '.authtype'));
88+
} elseif (!preg_match('/^[A-Za-z0-9-_.]+$/', $username)) {
89+
$messages->appendMessage(new Message(gettext('Illegal characters in key'), $ref . '.authtype'));
90+
} elseif (!preg_match('/^[A-Za-z0-9-_.]+$/', $password)) {
91+
$messages->appendMessage(new Message(gettext('Illegal characters in value'), $ref . '.authtype'));
92+
}
93+
break;
8194
}
8295
}
8396

src/opnsense/mvc/app/models/OPNsense/Firewall/Alias.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@
7575
<OptionValues>
7676
<Basic>Basic</Basic>
7777
<Bearer>Bearer</Bearer>
78+
<Header>Header</Header>
7879
</OptionValues>
7980
</authtype>
8081
<categories type="ModelRelationField">

src/opnsense/mvc/app/views/OPNsense/Firewall/alias.volt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -378,6 +378,10 @@
378378
case 'Bearer':
379379
$("#alias\\.password").show().attr('placeholder', '{{lang._('API token')}}');
380380
break;
381+
case 'Header':
382+
$("#alias\\.username").show().attr('placeholder', '{{lang._('HTTP Header')}}');
383+
$("#alias\\.password").show().attr('placeholder', '{{lang._('API token')}}');
384+
break;
381385
}
382386
});
383387
$("#alias\\.authtype").change();

src/opnsense/scripts/filter/lib/alias/uri.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@ def iter_addresses(self, url):
7171
req_opts['auth'] = requests.auth.HTTPBasicAuth(self._username, self._password)
7272
elif self._authtype == 'Bearer':
7373
req_opts['headers']['Authorization'] = f'Bearer {self._password}'
74+
elif self._authtype == 'Header' and self._username is not None:
75+
req_opts['headers'][self._username] = self._password
7476

7577
# fetch data
7678
try:

0 commit comments

Comments
 (0)