Skip to content

IP Whitelist leading to 500 error in API #2372

@Flo4604

Description

@Flo4604

Preliminary Checks

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

  1. Enable the enterprise plan in the db
  2. Visit the API settings and set some IP Whitelist
  3. When testing locally be sure to set a IP or comment out the whole part in apps/api/src/pkg/keys/service.ts
    CleanShot 2024-10-13 at 10 59 10@2x

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

Metadata

Metadata

Assignees

Labels

BugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions