Skip to content
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

"SQL query" module: running long queries from the Admin panel return "HTTP Error 404.15 - Not Found" #15780

Open
MarGraz opened this issue Apr 17, 2024 · 3 comments
Labels
Milestone

Comments

@MarGraz
Copy link
Contributor

MarGraz commented Apr 17, 2024

Describe the bug

When the "SQL Query" feature is active in Orchard Core 1.8.2, creating and attempting to run a long SQL query through "Search" > "Queries" > "All queries" results in an error when using the Run button:

HTTP Error 404.15 - Not Found. The request filtering module is configured to deny a request where the query string is too long

Instead, if a shorter query is first opened and then replaced by pasting the long query into the editor, it runs successfully.

As discussed in this conversation, the problem seems to be related on how the query is sent to the server. It is likely more appropriate to send the query as a POST request with the query in the body, rather than as a GET request with the query in the URL.

To Reproduce

Steps to reproduce the behavior:

  1. Run the project using Visual Studio with a PostgreSQL database;
  2. Enable the "SQL Query" feature;
  3. Navigate to "Search" > "Queries" and create a short SQL query;
  4. Create and save a longer SQL query;
  5. Attempt to run the long query from the Run button under "Search" > "Queries" > "All queries";
  6. Observe the error 404.15;
  7. Go back and copy the long query;
  8. Open and edit the short query;
  9. Paste the long query into the editor and run it by clicking the Query button;
  10. The long query executes without error.

Long query example:
I used a CAST() function named cast_text_to_jsonb because PostgreSQL does not support the default CAST(), as discussed here.

This query retrieves additional data from User using a CustomUserSettings content type, as detailed in the documentation. The data is stored in the Document DB table.

You can reproduce this issue with any long query. This is the one I used:

SELECT 
    UI."DocumentId", 
    UI."UserId", 
    UI."NormalizedUserName", 
    UI."NormalizedEmail", 
    STRING_AGG(UBRNI.RoleName, ',') AS RoleNames,
    STRING_AGG(casttotext(UBRNID.UserByRoleNameIndexId), ',') AS RoleIds,
    jsonb_extract_path_text(cast_text_to_jsonb(D."Content"), 'Properties', 'UserDetails', 'UserDetails', 'Name', 'Text') AS FirstName,
    jsonb_extract_path_text(cast_text_to_jsonb(D."Content"), 'Properties', 'UserDetails', 'UserDetails', 'Surname', 'Text') AS LastName,
    jsonb_extract_path_text(cast_text_to_jsonb(D."Content"), 'Properties', 'UserDetails', 'UserDetails', 'Phone', 'Text') AS Phone,
    jsonb_extract_path_text(cast_text_to_jsonb(D."Content"), 'Properties', 'UserDetails', 'UserDetails', 'WhatsApp', 'Text') AS WhatsApp,
    jsonb_extract_path_text(cast_text_to_jsonb(D."Content"), 'Properties', 'UserDetails', 'UserDetails', 'Street', 'Text') AS Street,
    jsonb_extract_path_text(cast_text_to_jsonb(D."Content"), 'Properties', 'UserDetails', 'UserDetails', 'StreetNumber', 'Text') AS StreetNumber,
    jsonb_extract_path_text(cast_text_to_jsonb(D."Content"), 'Properties', 'UserDetails', 'UserDetails', 'City', 'Text') AS City,
    jsonb_extract_path_text(cast_text_to_jsonb(D."Content"), 'Properties', 'UserDetails', 'UserDetails', 'ParamOne', 'Text') AS ParamOne,
    jsonb_extract_path_text(cast_text_to_jsonb(D."Content"), 'Properties', 'UserDetails', 'UserDetails', 'ParamTwo', 'Url') AS ParamTwo,
    jsonb_extract_path_text(cast_text_to_jsonb(D."Content"), 'Properties', 'UserDetails', 'UserDetails', 'ParamThree', 'Url') AS ParamThree,
    jsonb_extract_path_text(cast_text_to_jsonb(D."Content"), 'Properties', 'UserDetails', 'UserDetails', 'ParamFour', 'Url') AS ParamFour,
    jsonb_extract_path_text(cast_text_to_jsonb(D."Content"), 'Properties', 'UserDetails', 'UserDetails', 'Description', 'Text') AS Description,
    jsonb_extract_path_text(cast_text_to_jsonb(D."Content"), 'Properties', 'UserDetails', 'UserDetails', 'Logo', 'Paths') AS LogoPaths
FROM 
    "UserIndex" UI
JOIN 
    "Document" D ON UI."DocumentId" = D."Id"
JOIN 
    "UserByRoleNameIndex_Document" UBRNID ON UI."DocumentId" = UBRNID."DocumentId"
JOIN 
    "UserByRoleNameIndex" UBRNI ON UBRNID."UserByRoleNameIndexId" = UBRNI."Id"
GROUP BY 
    UI."DocumentId", 
    UI."UserId", 
    UI."NormalizedUserName", 
    UI."NormalizedEmail",
    D."Content"

Expected behavior

Click on Run should not return a 404.15 error. As demonstrated when editing an existing query or via the page "Search" > "Query" > "Run SQL Query".

Screenshots

This is the request URL that you can see in the screenshot:

https://localhost:44300/Admin/Queries/Sql/Query?query=U0VMRUNUIA0KICAgIFVJLiJEb2N1bWVudElkIiwgDQogICAgVUkuIlVzZXJJZCIsIA0KICAgIFVJLiJOb3JtYWxpemVkVXNlck5hbWUiLCANCiAgICBVSS4iTm9ybWFsaXplZEVtYWlsIiwgDQogICAgU1RSSU5HX0FHRyhVQlJOSS5Sb2xlTmFtZSwgJywnKSBBUyBSb2xlTmFtZXMsDQogICAgU1RSSU5HX0FHRyhjYXN0dG90ZXh0KFVCUk5JRC5Vc2VyQnlSb2xlTmFtZUluZGV4SWQpLCAnLCcpIEFTIFJvbGVJZHMsDQogICAganNvbmJfZXh0cmFjdF9wYXRoX3RleHQoY2FzdF90ZXh0X3RvX2pzb25iKEQuIkNvbnRlbnQiKSwgJ1Byb3BlcnRpZXMnLCAnVXNlckRldGFpbHMnLCAnVXNlckRldGFpbHMnLCAnTmFtZScsICdUZXh0JykgQVMgRmlyc3ROYW1lLA0KICAgIGpzb25iX2V4dHJhY3RfcGF0aF90ZXh0KGNhc3RfdGV4dF90b19qc29uYihELiJDb250ZW50IiksICdQcm9wZXJ0aWVzJywgJ1VzZXJEZXRhaWxzJywgJ1VzZXJEZXRhaWxzJywgJ1N1cm5hbWUnLCAnVGV4dCcpIEFTIExhc3ROYW1lLA0KICAgIGpzb25iX2V4dHJhY3RfcGF0aF90ZXh0KGNhc3RfdGV4dF90b19qc29uYihELiJDb250ZW50IiksICdQcm9wZXJ0aWVzJywgJ1VzZXJEZXRhaWxzJywgJ1VzZXJEZXRhaWxzJywgJ1Bob25lJywgJ1RleHQnKSBBUyBQaG9uZSwNCiAgICBqc29uYl9leHRyYWN0X3BhdGhfdGV4dChjYXN0X3RleHRfdG9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iLCANCiAgICBVSS4iTm9ybWFsaXplZFVzZXJOYW1lIiwgDQogICAgVUkuIk5vcm1hbGl6ZWRFbWFpbCIsDQogICAgRC4iQ29udGVudCI%3D

image

@Piedone
Copy link
Member

Piedone commented Apr 17, 2024

While you can configure IIS and Kestrel to accept long URLs, yes, a better solution (and otherwise a more appropriate use of HTTP verbs) would be to send a POST request.

Is this something you'd perhaps be interested in contributing?

@MarGraz
Copy link
Contributor Author

MarGraz commented May 2, 2024

@Piedone it will be my first code contribution, so please guide me 😊

@Piedone
Copy link
Member

Piedone commented May 2, 2024

Sure, and great! Start here: https://docs.orchardcore.net/en/latest/guides/contributing/contributing-code/. Then let me know if you have questions.

@sebastienros sebastienros added this to the 2.x milestone May 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants