IP Whitelist leading to 500 error in API
Preliminary Checks
-
[X] I have reviewed the documentation: https://unkey.com/docs
-
[X] I have searched for existing issues: https://github.com/unkeyed/unkey/issues
-
[X] This issue is not a question, general help request, or anything other than a bug report directly related to Unkey. Please ask questions in our Discord community: https://unkey.com/discord.
Reproduction / Replay Link (Optional)
No response
Issue Summary
When you have the enterprise plan, you have the function to allow IP Whitelisting. This can be done by inputting a list of CSV ips OR newline-separated ips.
Those IP's are then stored as a csv in the Database.
The issue is that the API tries to JSON parse this, which doesn't work as it's not a JSON string but a CSV, you have the function to allow IP Whitelisting. This can be done by inputting a list of CSV ips OR newline-separated ips
2024/10/12 19:18:44 error: {"error":{"code":"INTERNAL_SERVER_ERROR","docs":"https://unkey.dev/docs/api-reference/errors/code/INTERNAL_SERVER_ERROR","message":"Unexpected non-whitespace character after JSON at position 5 (line 1 column 6)","requestId":"req_3UhrGthbDURT4EZhkxZ7oriXsxdQ"}}
Steps to Reproduce
- Enable the enterprise plan in the db
- Visit the API settings and set some IP Whitelist
- When testing locally be sure to set a IP or comment out the whole part in apps/api/src/pkg/keys/service.ts
You can then call the verify key method as normal and see that you are getting a 500 error.
Expected behavior
To avoid getting a 500 error and the IP whitelist to work correctly.
So either the IP Whitelist has to be stored as a JSON array string or the API code has to be adjusted in order to parse csv.
Question: Do the currently non-deleted APIs with IP whitelisting enable have everything stored as CSV or JSON? If it's all CSV, it would be easier to adjust the API; otherwise, a script is needed to backfill from JSON to CSV or CSV to JSON.
Other information
No response
Screenshots
No response
Version info
Irrelevant
yup, we need to update this to parse as a CSV data.api.ipWhitelist.split(",").map(s=>s.trim()) should fix it
/assign
Assigned to @Flo4604! Please open a draft PR linking this issue within 48h ⚠️ If we can't detect a PR from you linking this issue in 48h, you'll be unassigned automatically 🕹️ Excited to have you ship this 🚀
also let's fix a related issue where you can bypass the frontend logic to add an ip whitelist even if you're not on the ee plan
/assign
This issue is already assigned to another person. Please find more issues here.
/assign
This issue is already assigned to another person. Please find more issues here.
/assign
This issue is already assigned to another person. Please find more issues here.
/award 150
Awarding Flo4604: 150 points 🕹️ Well done! Check out your new contribution on oss.gg/Flo4604