Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
conduwuit
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
🥺
conduwuit
Commits
423fc6da
Commit
423fc6da
authored
11 months ago
by
Jason Volk
Committed by
🥺
11 months ago
Browse files
Options
Downloads
Patches
Plain Diff
precompute cidr range denylist; move validator.
Signed-off-by:
Jason Volk
<
jason@zemos.net
>
parent
93c3e6de
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/service/globals/mod.rs
+21
-1
21 additions, 1 deletion
src/service/globals/mod.rs
src/service/sending/send.rs
+2
-11
2 additions, 11 deletions
src/service/sending/send.rs
with
23 additions
and
12 deletions
src/service/globals/mod.rs
+
21
−
1
View file @
423fc6da
...
...
@@ -14,6 +14,7 @@
use
base64
::{
engine
::
general_purpose
,
Engine
as
_
};
pub
use
data
::
Data
;
use
hickory_resolver
::
TokioAsyncResolver
;
use
ipaddress
::
IPAddress
;
use
regex
::
RegexSet
;
use
ruma
::{
api
::{
...
...
@@ -25,7 +26,7 @@
RoomVersionId
,
ServerName
,
UserId
,
};
use
tokio
::
sync
::{
broadcast
,
watch
::
Receiver
,
Mutex
,
RwLock
,
Semaphore
};
use
tracing
::{
error
,
info
};
use
tracing
::{
error
,
info
,
trace
};
use
tracing_subscriber
::{
EnvFilter
,
Registry
};
use
url
::
Url
;
...
...
@@ -46,6 +47,7 @@ pub struct Service<'a> {
pub
tracing_reload_handle
:
tracing_subscriber
::
reload
::
Handle
<
EnvFilter
,
Registry
>
,
pub
config
:
Config
,
pub
cidr_range_denylist
:
Vec
<
IPAddress
>
,
keypair
:
Arc
<
ruma
::
signatures
::
Ed25519KeyPair
>
,
jwt_decoding_key
:
Option
<
jsonwebtoken
::
DecodingKey
>
,
pub
resolver
:
Arc
<
resolver
::
Resolver
>
,
...
...
@@ -138,10 +140,18 @@ pub fn load(
argon2
::
Params
::
new
(
19456
,
2
,
1
,
None
)
.expect
(
"valid parameters"
),
);
let
mut
cidr_range_denylist
=
Vec
::
new
();
for
cidr
in
config
.ip_range_denylist
.clone
()
{
let
cidr
=
IPAddress
::
parse
(
cidr
)
.expect
(
"valid cidr range"
);
trace!
(
"Denied CIDR range: {:?}"
,
cidr
);
cidr_range_denylist
.push
(
cidr
);
}
let
mut
s
=
Self
{
tracing_reload_handle
,
db
,
config
:
config
.clone
(),
cidr_range_denylist
,
keypair
:
Arc
::
new
(
keypair
),
resolver
:
resolver
.clone
(),
client
:
client
::
Client
::
new
(
config
,
&
resolver
),
...
...
@@ -424,6 +434,16 @@ pub fn well_known_server(&self) -> &Option<OwnedServerName> { &self.config.well_
pub
fn
unix_socket_path
(
&
self
)
->
&
Option
<
PathBuf
>
{
&
self
.config.unix_socket_path
}
pub
fn
valid_cidr_range
(
&
self
,
ip
:
&
IPAddress
)
->
bool
{
for
cidr
in
&
self
.cidr_range_denylist
{
if
cidr
.includes
(
ip
)
{
return
false
;
}
}
true
}
pub
fn
shutdown
(
&
self
)
{
self
.shutdown
.store
(
true
,
atomic
::
Ordering
::
Relaxed
);
// On shutdown
...
...
This diff is collapsed.
Click to expand it.
src/service/sending/send.rs
+
2
−
11
View file @
423fc6da
...
...
@@ -536,17 +536,8 @@ fn validate_destination_ip_literal(destination: &ServerName) -> Result<()> {
}
fn
validate_ip
(
ip
:
&
IPAddress
)
->
Result
<
()
>
{
let
cidr_ranges_s
=
services
()
.globals
.ip_range_denylist
()
.to_vec
();
let
mut
cidr_ranges
:
Vec
<
IPAddress
>
=
Vec
::
new
();
for
cidr
in
cidr_ranges_s
{
cidr_ranges
.push
(
IPAddress
::
parse
(
cidr
)
.expect
(
"we checked this at startup"
));
}
trace!
(
"List of pushed CIDR ranges: {:?}"
,
cidr_ranges
);
for
cidr
in
cidr_ranges
{
if
cidr
.includes
(
ip
)
{
return
Err
(
Error
::
BadServerResponse
(
"Not allowed to send requests to this IP"
));
}
if
!
services
()
.globals
.valid_cidr_range
(
ip
)
{
return
Err
(
Error
::
BadServerResponse
(
"Not allowed to send requests to this IP"
));
}
Ok
(())
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment