diff --git a/docs/API.md b/docs/API.md index d4281efe2..2b7750100 100644 --- a/docs/API.md +++ b/docs/API.md @@ -1208,9 +1208,15 @@ Omitting params: Trying to add a user over non-localhost: ```json { - "result": 0, "id": 1, - "jsonrpc": "2.0" + "jsonrpc": "2.0", + "error": { + "code": -32603, + "data": { + "remote_ip": "10.0.0.1" + }, + "message": "Call to \"add_api_user\" method not permitted from a remote IP" + } } ``` diff --git a/lib/Zonemaster/Backend/RPCAPI.pm b/lib/Zonemaster/Backend/RPCAPI.pm index 76e20add2..5f3c178a9 100644 --- a/lib/Zonemaster/Backend/RPCAPI.pm +++ b/lib/Zonemaster/Backend/RPCAPI.pm @@ -575,6 +575,12 @@ sub add_api_user { if ( $allow ) { $result = 1 if ( $self->{db}->add_api_user( $params->{username}, $params->{api_key} ) eq '1' ); } + else { + die Zonemaster::Backend::Error::PermissionDenied->new( + message => 'Call to "add_api_user" method not permitted from a remote IP', + data => { remote_ip => $remote_ip } + ); + } }; if ($@) { handle_exception( $@ );