-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: Switch from MAC address stored in Nautobot asset_tag to custom field #502
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please rebase to pass CI.
also - minor suggestion:
formatted_list = json.dumps(list(mac_addresses)) | ||
pattern = "|".join(mac_addresses) | ||
|
||
query = ( | ||
"""{ | ||
devices(asset_tag: %s){ | ||
devices(cf_chassis_mac_address__re: "(%s)"){ | ||
id name | ||
mac: asset_tag | ||
mac: cf_chassis_mac_address | ||
location { id name } | ||
rack { id name } | ||
} | ||
}""" | ||
% formatted_list | ||
% pattern |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
string interpolation creates the GraphQL injection vulnerability. For example, one could say
mac_addresses={"a.*", "dummy_input\") { devices { id passwords } } #"}
Consider replacing this with query variables (untested):
query = """
query($pattern: String!) {
devices(cf_chassis_mac_address__re: $pattern) {
id name
mac: cf_chassis_mac_address
location { id name }
rack { id name }
}
}
"""
variables = {"pattern": "|".join(mac_addresses)}
result = nautobot.graphql.query(query, variables=variables)
python/understack-workflows/understack_workflows/nautobot_device.py
Outdated
Show resolved
Hide resolved
I updated all the queries to avoid suspicion due to string interpolation. |
We have to change the graphql filter - you could search in Nautobot's built-in string attributes by passing an array of possible values to find, but that doesn't work for custom fields.
Learn the lessons of the 1990s and use "variables", as God intended.
Use the "variables" feature to avoid string interpolation in making these queries.
78582d8
to
84afca5
Compare
The custom fields have been added to ansible, and to the dev and staging environments, and in those environments the data has been copied from the asset_tag field to the new custom field.
We had to change how we do the graphql filter - you could search in Nautobot's built-in string attributes by passing an array of possible values to find, but that doesn't work for custom fields.