Hi , I’m experiencing an issue related to url_mapp...
# permit-saas
t
Hi , I’m experiencing an issue related to url_mapping. I currently have 5 URL mapping configurations (Proxy Configs), and the issue occurs specifically when I create mappings using regex. The problem is that
url_type
is not being saved correctly
. For example, this mapping is saved properly and appears with the regex badge on the frontend:
Copy code
{
  "url": "https?://api.abclojistik.com/test/api/erp/(?:tr|en)/reports/?.*$",
  "url_type": "regex",
  "http_method": "get",
  "resource": "erp_report",
  "headers": {},
  "action": "read",
  "priority": null
}
However, this one gets saved with
"url_type": null
even though it is also a regex, and the frontend still shows it with the regex badge:
Copy code
{
  "url": "https?://api.abclojistik.com/test/api/hub/(?:tr|en)/orders/?.*$",
  "url_type": null,
  "http_method": "patch",
  "resource": "hub_order",
  "headers": {},
  "action": "update",
  "priority": null
}
When I fetch this configuration from the Permit.io API, it does not indicate that it’s a regex. I’m not sure if this inconsistency is the root cause, but I’m also getting a PDP crash when calling the
allowed_url
endpoint. I’ve attached the PDP crash logs to this message. it gives error about Horizon server. But this error occured after i added new url_mappings. I need to resolve this issue as soon as possible. Any help would be greatly appreciated.
a
Hi @Taha ÇEKEN, I'm an AI assistant for Permit.io. I'll analyze available sources and get back to you shortly.
I see you're experiencing issues with regex URL mapping configurations and PDP crashes. Based on the documentation, the
url_type
field must be explicitly set to
"regex"
for regex pattern matching to work properly (1) . When creating proxy configurations with regex patterns, the API call should include
url_type: "regex"
explicitly :
Copy code
{
  "url": "^<https://api>\\.example\\.com/api/v1/users/(?P<user_id>[0-9]+) /profile$",
  "http_method": "post",
  "resource": "users",
  "action": "update",
  "url_type": "regex"
}
The inconsistency where one mapping saves with
"url_type": "regex"
and another with
"url_type": null
despite both being regex patterns suggests the
url_type
field isn't being set correctly during creation. According to the documentation, regex URL mapping is only available through the Permit.io API & PDP API , and requires PDP version 0.8.0 or higher for simple URL mapping support . To check permissions with regex URL mapping, ensure your PDP is running with proper configuration :
Copy code
docker run -it \
  -p 7766:7000 \
  --env PDP_API_KEY=permit_key_{your_permit_env_key} \
  --env PDP_DEBUG=True \
  permitio/pdp-v2:latest
To help our engineers investigate this bug further, could you please provide: 1. Which Workspace / Project / Env you are using 2. What specific calls you're performing (as SDK code or CURL) when creating these proxy configs 3. Which PDP version you are running (you can check this in your container logs) 4. The relevant PDP logs showing the crash when calling the
allowed_url
endpoint This information will help diagnose why the
url_type
field isn't being saved consistently and why the PDP is crashing.
To learn more, see the sources I considered: [[1] Regex URL Mapping Check](https://docs.permit.io/foaz/regex-url-mapping-check)
t
workspace : abclojistik.com project : decision-engine Env : testing PDP ver : 0.9.7 OPA ver: 1.4.2 also provided sample regex url is not valid. ^https://api\\.example\\.com/api/v1/users/(?P<user_id>[0-9]+)/profile$ frontend of permitio says Must be a valid regex pattern.
{ "url": "https?:<//api.abclojistik.com/test/api/hub/(?:tr%7Cen)/orders/?.*$>", "url_type": "regex", "http_method": "get", "resource": "hub_order", "headers": {}, "action": "read", "priority": null }, { "url": "https?:<//api.abclojistik.com/test/api/hub/(?:tr%7Cen)/orders/?.*$>", "url_type": "regex", "http_method": "post", "resource": "hub_order", "headers": {}, "action": "create", "priority": null }, { "url": "https?:<//api.abclojistik.com/test/api/hub/(?:tr%7Cen)/orders/?.*$>", "url_type": "regex", "http_method": "put", "resource": "hub_order", "headers": {}, "action": "update", "priority": null }, { "url": "https?:<//api.abclojistik.com/test/api/hub/(?:tr%7Cen)/users/?.*$>", "url_type": "regex", "http_method": "get", "resource": "hub_user", "headers": {}, "action": "read", "priority": null }, @Ask Inkeep can you give me better regex for this endpoints. i want to cover sub endpoints inside these endpoints. regex or another vay according to the docs.
a
Thanks for tagging me @Taha ÇEKEN. I'll look through relevant sources and get back to you shortly.
Looking at your regex patterns, I can see the issue. Your patterns have HTML-encoded characters (
<
and
>
) and URL-encoded pipe symbols (
%7C
) which are causing validation problems. Based on the documentation (1) , here are the corrected regex patterns for your endpoints: For the hub orders endpoints:
Copy code
{
  "url": "^https?://api\\.abclojistik\\.com/test/api/hub/(?:tr|en) /orders(?:/.*) ?$",
  "url_type": "regex",
  "http_method": "get",
  "resource": "hub_order",
  "action": "read"
}
For the hub users endpoint:
Copy code
{
  "url": "^https?://api\\.abclojistik\\.com/test/api/hub/(?:tr|en) /users(?:/.*) ?$",
  "url_type": "regex",
  "http_method": "get",
  "resource": "hub_user",
  "action": "read"
}
Key corrections made: 1. Removed HTML encoding (
<
and
>
) 2. Fixed URL-encoded pipe (
%7C
→
|
) 3. Used
(?:/.*) ?
to match optional sub-paths (cleaner than
/?.*$
) 4. Added
^
at the start for complete URL matching 5. Properly escaped dots in the domain with
\\.
Important note from the documentation : When sending these patterns via the API as JSON, you need to escape backslashes. So
\.
becomes
\\.
in the JSON payload. For your PDP crash issue, since you're running PDP v0.9.7 which is above the required v0.8.0 , the crashes might be related to the malformed regex patterns. Once you fix the patterns, the PDP should handle the
allowed_url
endpoint correctly. To help our engineers investigate the PDP crash further: 1. Workspace: abclojistik.com 2. Project: decision-engine 3. Env: testing 4. PDP version: 0.9.7 5. Could you share the actual PDP crash logs when calling
allowed_url
?
To learn more, see the sources I considered: [[1] Regex URL Mapping Check](https://docs.permit.io/foaz/regex-url-mapping-check)
a
Hey @Taha ÇEKEN, thanks for reaching out. Will circle back to you soon
🙏 1
t
i have updated my url mappings as you suggested but still same. { "url": "^https?://api\\.abclojistik\\.com/test/api/hub/(?:tr|en)/orders(?:/.*)?$", "url_type": "regex", "http_method": "get", "resource": "hub_order", "headers": {}, "action": "read", "priority": null }, { "url": "^https?://api\\.abclojistik\\.com/test/api/hub/(?:tr|en)/orders(?:/.*)?$", "url_type": "regex", "http_method": "post", "resource": "hub_order", "headers": {}, "action": "create", "priority": null }, { "url": "^https?://api\\.abclojistik\\.com/test/api/hub/(?:tr|en)/orders(?:/.*)?$", "url_type": "regex", "http_method": "put", "resource": "hub_order", "headers": {}, "action": "update", "priority": null }, when i use send request to the allowed_url endpoint i get. Permit.io responded with status 504 pdp crashes creates another pdp instance i can see that in monitoring page
Copy code
No data - check the PDP logs for more information.
also has that log inside audit-log. my production environment runs without any error. with this kind of url mappings
Copy code
{
        "url": "https?://api.abex.com.tr/test/api/booking/(?:tr|en)/voyages/?.*$",
        "url_type": "regex",
        "http_method": "get",
        "resource": "bkg_voyage",
        "headers": {},
        "action": "read",
        "priority": null
      },
      {
        "url": "<https://api.abex.com.tr/test/api/booking/{lang}/bookings/{release_no}/get-changes>",
        "url_type": null,
        "http_method": "get",
        "resource": "bkg_booking",
        "headers": {},
        "action": "read",
        "priority": null
      },
what should i do ? @Ask Inkeep
a
Thanks for tagging me @Taha ÇEKEN. I'll look through relevant sources and get back to you shortly.
The 504 timeout and PDP crashes you're experiencing are likely related to the regex pattern complexity and how the PDP is handling them. Let me help you troubleshoot this. Looking at your working production example versus the failing patterns, I notice your production uses a mix of regex (
url_type: "regex"
) and simple URL mapping (
url_type: null
with
{lang}
placeholders) . For simple URL mapping with path parameters, you should use the
{var}
syntax without regex (1) :
Copy code
{
  "url": "<https://api.abclojistik.com/test/api/hub/{lang}/orders>",
  "url_type": null,
  "http_method": "get",
  "resource": "hub_order",
  "action": "read"
}
If you need to match sub-paths with simple URL mapping, the documentation shows you can use templating like
<http://example.com/v1/{customer_id}/payments|example.com/v1/{customer_id}/payments>
. For debugging the PDP crash, you can enable debug mode to get more detailed logs (2) :
Copy code
docker run -it \
  -p 7766:7000 \
  --env PDP_API_KEY=permit_key_{your_permit_env_key} \
  --env PDP_DEBUG=True \
  permitio/pdp-v2:latest
To help our engineers investigate this PDP crash bug: 1. ​*Workspace / Project / Env*​: abclojistik.com / decision-engine / testing 2. ​*What calls are you performing*​: Can you share the exact CURL command you're using to call the
allowed_url
endpoint? 3. ​*PDP version*​: 0.9.7 (OPA 1.4.2) 4. ​*PDP logs*​: Please share the full PDP container logs when the crash occurs - you can get these with
docker logs <container_id>
The 504 timeout suggests the PDP is taking too long to evaluate the regex patterns. Try simplifying to simple URL mapping first to isolate if regex complexity is the issue.
To learn more, see the sources I considered: [[1] Simple URL Mapping Check](https://docs.permit.io/foaz/url-mapping-check) [[2] Configurations](https://docs.permit.io/concepts/pdp/configuration)
t
@Alon Boshi i have tried every solution i find but none of them works. i was using this url_mapping feature with single tenant. i created new url_mappings for my new application. after i sent my first request to the allowed url. for another tenant i get this error. Permit.io error: Connection error occurred while connecting to horizon server than it created another instance of pdp. But this is not working. and it gives "error": "Permit.io responded with status 502", i need a solution
a
Saw your message — I’ll get back to you as soon as I can.
I was able to test this in my env and I have a working example via the API. The UI currently has filed validation that won't let you save a non-https or regex based url. Take a look at this guide/tutorial to see how to configure all these: https://docs.permit.io/foaz/regex-url-mapping-check/
Copy code
curl --location '<https://api.permit.io/v2/facts/support/urlmapping/proxy_configs>' \
--header 'Content-Type: application/json' \
--header 'Accept: application/json' \
--header 'Authorization: Bearer permit_key_yourKey' \
--data '{
  "secret": "notUsed",
  "key": "test_http",
  "name": "test_http",
  "auth_mechanism": "Bearer",
  "mapping_rules": [
    {
        "url": "^<http://localhost/users/(?P><user_id>[0-9]+)/profile$",
        "http_method": "post",
        "resource": "customers",
        "action": "create",
        "url_type": "regex",
        "priority": "1"
    }
  ]
}'
✅ 1