Invalid json types cause stacktrace

Bug #1471966 reported by Tristan Cacqueray
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
neutron
Expired
Undecided
Unassigned

Bug Description

Incorrect json input cause error instead of being invalidated properly:

Type error in dns_nameservers raise keyerror:

ERROR neutron.api.v2.resource [req-be58f6e1-db2f-4b2e-9620-afb49bdd4552 demo d1da3f8632e3413b915eda78899806d7] create failed
Traceback (most recent call last):
  File "/opt/stack/neutron/neutron/api/v2/resource.py", line 87, in resource
    result = method(request=request, **args)
  File "/opt/stack/neutron/neutron/api/v2/base.py", line 379, in create
    allow_bulk=self._allow_bulk)
  File "/opt/stack/neutron/neutron/api/v2/base.py", line 637, in prepare_request_body
    attr_vals['validate'][rule])
  File "/opt/stack/neutron/neutron/api/v2/attributes.py", line 275, in _validate_nameservers
    msg = _validate_ip_or_hostname(host)
  File "/opt/stack/neutron/neutron/api/v2/attributes.py", line 257, in _validate_ip_or_hostname
    name_err = _validate_hostname(host)
  File "/opt/stack/neutron/neutron/api/v2/attributes.py", line 370, in _validate_hostname
    trimmed = data if data[-1] != '.' else data[:-1]
TRACE neutron.api.v2.resource KeyError: -1
TRACE neutron.api.v2.resource·

Steps to reproduce:
token=$(keystone token-get | grep ' id ' | awk '{ print $4}')
curl -H "X-Auth-Token:${token}" -H 'Content-Type:application/json' -X POST http://localhost:9696//v2.0/subnets.json \
 -d '{"subnet": {"dns_nameservers": [{}], "cidr": "192.168.0.1/24", "network_id": "aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa", "ip_version": "4"}}'; echo

Various sql errors with security-group params:

Trace:
ERROR neutron.api.v2.resource [req-0f32e171-029c-465a-872e-d3533fc191c7 demo 4a2f46b3469240589af5db1ffd3e56e7] create failed
TRACE neutron.api.v2.resource Traceback (most recent call last):
TRACE neutron.api.v2.resource File "/opt/stack/neutron/neutron/api/v2/resource.py", line 87, in resource
TRACE neutron.api.v2.resource result = method(request=request, **args)
TRACE neutron.api.v2.resource File "/opt/stack/neutron/neutron/api/v2/base.py", line 448, in create
TRACE neutron.api.v2.resource obj = obj_creator(request.context, **kwargs)
TRACE neutron.api.v2.resource File "/opt/stack/neutron/neutron/db/securitygroups_db.py", line 137, in create_security_group
TRACE neutron.api.v2.resource context.session.add(egress_rule)
TRACE neutron.api.v2.resource File "/usr/lib/python2.7/dist-packages/sqlalchemy/orm/session.py", line 447, in __exit__
TRACE neutron.api.v2.resource self.rollback()
TRACE neutron.api.v2.resource File "/usr/lib/python2.7/dist-packages/sqlalchemy/util/langhelpers.py", line 58, in __exit__
TRACE neutron.api.v2.resource compat.reraise(exc_type, exc_value, exc_tb)
TRACE neutron.api.v2.resource File "/usr/lib/python2.7/dist-packages/sqlalchemy/orm/session.py", line 444, in __exit__
TRACE neutron.api.v2.resource self.commit()
TRACE neutron.api.v2.resource File "/usr/lib/python2.7/dist-packages/sqlalchemy/orm/session.py", line 354, in commit
TRACE neutron.api.v2.resource self._prepare_impl()
TRACE neutron.api.v2.resource File "/usr/lib/python2.7/dist-packages/sqlalchemy/orm/session.py", line 334, in _prepare_impl
TRACE neutron.api.v2.resource self.session.flush()
TRACE neutron.api.v2.resource File "/usr/lib/python2.7/dist-packages/sqlalchemy/orm/session.py", line 1818, in flush
TRACE neutron.api.v2.resource self._flush(objects)
TRACE neutron.api.v2.resource File "/usr/lib/python2.7/dist-packages/sqlalchemy/orm/session.py", line 1936, in _flush
TRACE neutron.api.v2.resource transaction.rollback(_capture_exception=True)
TRACE neutron.api.v2.resource File "/usr/lib/python2.7/dist-packages/sqlalchemy/util/langhelpers.py", line 58, in __exit__
TRACE neutron.api.v2.resource compat.reraise(exc_type, exc_value, exc_tb)
TRACE neutron.api.v2.resource File "/usr/lib/python2.7/dist-packages/sqlalchemy/orm/session.py", line 1900, in _flush
TRACE neutron.api.v2.resource flush_context.execute()
TRACE neutron.api.v2.resource File "/usr/lib/python2.7/dist-packages/sqlalchemy/orm/unitofwork.py", line 372, in execute
TRACE neutron.api.v2.resource rec.execute(self)
TRACE neutron.api.v2.resource File "/usr/lib/python2.7/dist-packages/sqlalchemy/orm/unitofwork.py", line 525, in execute
TRACE neutron.api.v2.resource uow
TRACE neutron.api.v2.resource File "/usr/lib/python2.7/dist-packages/sqlalchemy/orm/persistence.py", line 64, in save_obj
TRACE neutron.api.v2.resource table, insert)
TRACE neutron.api.v2.resource File "/usr/lib/python2.7/dist-packages/sqlalchemy/orm/persistence.py", line 541, in _emit_insert_statements
TRACE neutron.api.v2.resource execute(statement, multiparams)
TRACE neutron.api.v2.resource File "/usr/lib/python2.7/dist-packages/sqlalchemy/engine/base.py", line 662, in execute
TRACE neutron.api.v2.resource params)
TRACE neutron.api.v2.resource File "/usr/lib/python2.7/dist-packages/sq
TRACE neutron.api.v2.resource compiled_sql, distilled_params
TRACE neutron.api.v2.resource File "/usr/lib/python2.7/dist-packages/sqlalchemy/engine/base.py", line 874, in _execute_context
TRACE neutron.api.v2.resource context)
TRACE neutron.api.v2.resource File "/usr/local/lib/python2.7/dist-packages/oslo/db/sqlalchemy/compat/handle_error.py", line 125, in _handle_dbapi_exception
TRACE neutron.api.v2.resource six.reraise(type(newraise), newraise, sys.exc_info()[2])
TRACE neutron.api.v2.resource File "/usr/local/lib/python2.7/dist-packages/oslo/db/sqlalchemy/compat/handle_error.py", line 102, in _handle_dbapi_exception
TRACE neutron.api.v2.resource per_fn = fn(ctx)
TRACE neutron.api.v2.resource File "/usr/local/lib/python2.7/dist-packages/oslo/db/sqlalchemy/exc_filters.py", line 323, in handler
TRACE neutron.api.v2.resource context.is_disconnect)
TRACE neutron.api.v2.resource File "/usr/local/lib/python2.7/dist-packages/oslo/db/sqlalchemy/exc_filters.py", line 278, in _raise_for_remaining_DBAPIError
TRACE neutron.api.v2.resource raise exception.DBError(error)
TRACE neutron.api.v2.resource DBError: (ProgrammingError) (1064, "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '), '')' at line 1") 'INSERT INTO securitygroups (tenant_id, id, name, description) VALUES (%s, %s, %s, %s)' ('4a2f46b3469240589af5db1ffd3e56e7', '35ba859f-475d-4afb-8c36-a4d3b434aeb9', [], '')

Steps to reproduce:
token=$(keystone token-get | grep ' id ' | awk '{ print $4}')
curl -H "X-Auth-Token:${token}" -H 'Content-Type:application/json' -X POST http://10.43.97.9:9696//v2.0/security-groups.json -d '{"security_group": {"name": []}}'; echo

Attribute error when security group name is list:

Trace:
ERROR neutron.api.v2.resource [req-3dc98a3c-6af2-498e-87bb-e09de31f0266 ] create failed
TRACE neutron.api.v2.resource Traceback (most recent call last):
TRACE neutron.api.v2.resource File "/usr/lib/python2.7/site-packages/neutron/api/v2/resource.py", line 83, in resource
TRACE neutron.api.v2.resource result = method(request=request, **args)
TRACE neutron.api.v2.resource File "/usr/lib/python2.7/site-packages/neutron/api/v2/base.py", line 391, in create
TRACE neutron.api.v2.resource allow_bulk=self._allow_bulk)
TRACE neutron.api.v2.resource File "/usr/lib/python2.7/site-packages/neutron/api/v2/base.py", line 652, in prepare_request_body
TRACE neutron.api.v2.resource attr_vals['validate'][rule])
TRACE neutron.api.v2.resource File "/usr/lib/python2.7/site-packages/neutron/extensions/securitygroup.py", line 177, in _validate_name_not_default
TRACE neutron.api.v2.resource if data.lower() == "default":
TRACE neutron.api.v2.resource AttributeError: 'list' object has no attribute 'lower'

Steps to reproduce:
token=$(keystone token-get | grep ' id ' | awk '{ print $4}')
curl -H "X-Auth-Token:${token}" -H 'Content-Type:application/json' -H 'Accept:application/json' -X POST http://localhost:9696/v2.0/security-groups.json -d '{"security_group": {"name": []}}'

Typerror when security group id is a dict

Trace:
TRACE neutron.api.v2.resource Traceback (most recent call last):
TRACE neutron.api.v2.resource File "/usr/lib/python2.7/site-packages/neutron/api/v2/resource.py", line 83, in resource
TRACE neutron.api.v2.resource result = method(request=request, **args)
TRACE neutron.api.v2.resource File "/usr/lib/python2.7/site-packages/neutron/api/v2/base.py", line 461, in create
TRACE neutron.api.v2.resource obj = obj_creator(request.context, **kwargs)
TRACE neutron.api.v2.resource File "/usr/lib/python2.7/site-packages/neutron/db/securitygroups_rpc_base.py", line 73, in create_security_group_rule
TRACE neutron.api.v2.resource bulk_rule)[0]
TRACE neutron.api.v2.resource File "/usr/lib/python2.7/site-packages/neutron/db/securitygroups_db.py", line 290, in create_security_group_rule_bulk_native
TRACE neutron.api.v2.resource context, security_group_rule)
TRACE neutron.api.v2.resource File "/usr/lib/python2.7/site-packages/neutron/db/securitygroups_db.py", line 365, in _validate_security_group_rules
TRACE neutron.api.v2.resource new_rules.add(rule['security_group_id'])
TRACE neutron.api.v2.resource TypeError: unhashable type: 'dict'

Steps to reproduce:
token=$(keystone token-get | grep ' id ' | awk '{ print $4}')
curl -H "X-Auth-Token:${token}" -H 'Content-Type:application/json' -H 'Accept:application/json' -X POST http://localhost:9696//v2.0/security-group-rules.json -d '{"security_group_rule": {"direction": "egress", "security_group_id": {}}}'

Impact:
Raise random exception instead of NeutronError

description: updated
Revision history for this message
Louis Taylor (kragniz) wrote :

I can reproduce this on master.

Changed in neutron:
status: New → Confirmed
Revision history for this message
Martin Hickey (martin-hickey) wrote :

Hi Tristan,

I have tested this in the current master code and it is invalidating the request and returning a suitable error as follows:
$curl -g -i -X POST http://X.X.X.X:9696/v2.0/subnets.json -H "User-Agent: python-neutronclient" -H "Content-Type: application/json" -H "Accept: application/json" -H "X-Auth-Token: ${token}" -d '{"subnet":{"network_id": "dd5e13cc-d455-45fc-a2c8-0958a8b4834b", "ip_version": 4, "cidr": "10.0.40.0/24", "dns_nameservers": [{}], "name": "tst-subnet3"}}'
HTTP/1.1 400 Bad Request
Content-Length: 179
Content-Type: application/json; charset=UTF-8
X-Openstack-Request-Id: req-fe40fccd-e562-4048-abd6-3726cc11dc0a
Date: Wed, 04 Nov 2015 13:52:01 GMT

{"NeutronError": {"message": "Invalid input for dns_nameservers. Reason: '{}' is not a valid nameserver. '{}' is not a valid IP address.", "type": "HTTPBadRequest", "detail": ""}}

Could you provide more details on what version of OpenStack did you see the bug?

Thanks,
Martin

Changed in neutron:
status: Confirmed → Incomplete
Revision history for this message
Launchpad Janitor (janitor) wrote :

[Expired for neutron because there has been no activity for 60 days.]

Changed in neutron:
status: Incomplete → Expired
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.