travel, import API: Verify that payload is a hash
This commit is contained in:
parent
934a9ac21a
commit
c8695ecb1c
1 changed files with 26 additions and 4 deletions
|
@ -170,13 +170,24 @@ sub travel_v1 {
|
|||
my ($self) = @_;
|
||||
|
||||
my $payload = $self->req->json;
|
||||
|
||||
if ( not $payload or ref($payload) ne 'HASH' ) {
|
||||
$self->render(
|
||||
json => {
|
||||
success => \0,
|
||||
error => 'Malformed JSON',
|
||||
},
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
my $api_token = $payload->{token} // '';
|
||||
|
||||
if ( $api_token !~ qr{ ^ (?<id> \d+ ) - (?<token> .* ) $ }x ) {
|
||||
$self->render(
|
||||
json => {
|
||||
success => \0,
|
||||
error => 'Malformed JSON or malformed token',
|
||||
error => 'Malformed token',
|
||||
},
|
||||
);
|
||||
return;
|
||||
|
@ -339,13 +350,24 @@ sub import_v1 {
|
|||
my ($self) = @_;
|
||||
|
||||
my $payload = $self->req->json;
|
||||
|
||||
if ( not $payload or ref($payload) ne 'HASH' ) {
|
||||
$self->render(
|
||||
json => {
|
||||
success => \0,
|
||||
error => 'Malformed JSON',
|
||||
},
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
my $api_token = $payload->{token} // '';
|
||||
|
||||
if ( $api_token !~ qr{ ^ (?<id> \d+ ) - (?<token> .* ) $ }x ) {
|
||||
$self->render(
|
||||
json => {
|
||||
success => \0,
|
||||
error => 'Malformed JSON or malformed token',
|
||||
error => 'Malformed token',
|
||||
},
|
||||
);
|
||||
return;
|
||||
|
|
Loading…
Reference in a new issue