Reinstate bypass of IP restriction allowing access to restricted group snippets

Problem

Original issue: #499487 (closed)

Fix bypass of IP restriction allowing access to... (!175332 - merged) caused an Postgres error for some ip addresses.

It was reverted via Revert "Merge branch '499487/restricted-ip' int... (!176949 - merged).

When the provided range is incorrect (for example 1.1.1.1/22), then the query raises a postgres error:

SELECT range::cidr FROM ip_restrictions;
ERROR:  invalid cidr value: "1.1.1.1/22"
DETAIL:  Value has bits set to right of mask.

Sentry errors:

Suggestions

  • Update code to handle cases when an ip restriction range is incorrect.
  • Add a test to ensure that invalid ip range doesn't break the query.
Edited by Vasilii Iakliushin