Added new InvalidParamError class for handling bad named parameters.
Previously, InvalidJsonError was being used mistakenly for this which is misleading considering no JSON was involved.
This commit is contained in:
@@ -46,12 +46,12 @@ module Dns
|
||||
id = params[:id]
|
||||
|
||||
unless BeEF::Filters.alphanums_only?(id)
|
||||
raise InvalidJsonError, 'Invalid id passed to endpoint /api/dns/rule/:id'
|
||||
raise InvalidParamError, 'Invalid "id" parameter passed to endpoint /api/dns/rule/:id'
|
||||
end
|
||||
|
||||
result = BeEF::Extension::Dns::Server.instance.get_rule(id)
|
||||
result.to_json
|
||||
rescue InvalidJsonError => e
|
||||
rescue InvalidParamError => e
|
||||
print_error e.message
|
||||
halt 400
|
||||
rescue StandardError => e
|
||||
@@ -123,11 +123,11 @@ module Dns
|
||||
id = params[:id]
|
||||
|
||||
unless BeEF::Filters.alphanums_only?(id)
|
||||
raise InvalidJsonError, 'Invalid id passed to endpoint /api/dns/rule/:id'
|
||||
raise InvalidParamError, 'Invalid "id" parameter passed to endpoint /api/dns/rule/:id'
|
||||
end
|
||||
|
||||
BeEF::Extension::Dns::Server.instance.remove_rule(id)
|
||||
rescue InvalidJsonError => e
|
||||
rescue InvalidParamError => e
|
||||
print_error e.message
|
||||
halt 400
|
||||
rescue StandardError => e
|
||||
@@ -223,6 +223,17 @@ module Dns
|
||||
|
||||
end
|
||||
|
||||
# Raised when an invalid named parameter is passed to an /api/dns handler.
|
||||
class InvalidParamError < StandardError
|
||||
|
||||
DEFAULT_MESSAGE = 'Invalid parameter passed to /api/dns handler'
|
||||
|
||||
def initialize(message = nil)
|
||||
super(message || DEFAULT_MESSAGE)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user