-
Notifications
You must be signed in to change notification settings - Fork 458
Error pages return HTTP 200 instead of correct status codes (403, 404, 500) #4132
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
Comments
Hi @kerojohan. HTTP 404 errors for missing identifiers should be working correctly as of #2816. I don't know about the other errors, and I'm not sure if navigating directly to the error page is a good test? |
Hi @alanorth, Looking at the issue you referenced, it might actually be related to the same problem I'm experiencing. Direct access to those pages, or any non-existent path, should return a 404,403 or 500 status code. I was testing with this URL: https://demo.dspace.org/test — since the page doesn't exist, I expected to receive a 404, but instead I got a 200 status. Best regards, |
Yes, this may be. #2816 seems to only have fixed 404 responses for missing DSpace objects. |
(I've had a look at this, but I can't find a solution yet.) #2816 might also be related to the whole status code complex, but in this case I think this change might be more relevant: #3682 As the server-side rendered pages are restricted to a few pages/paths, the "ServerResponseService" can't set the response status code on the server, which seems to be necessary to get a real 404 status code back to the client! If you call any route that isn't registered, like "/this-route-does-not-exist", it'll never be rendered on the server side (check out the "ssr.paths" config to see which paths are rendered on the server side). Just for testing purposes, I reverted the "server.ts" to this line: |
If this is a side effect of #3682, then it might be (temporarily) worked around by disabling that feature. You can disable that feature by using this configuration (in your
That setting says to use SSR for all paths. Alternatively, it could be that we need to add all the 403/404/500 error pages into the default setting like this:
If someone has a chance to try these settings, please report back to let us know if they have any impact on the behavior. |
I've been able to verify this bug is caused by #3682. If you disable the default settings in #3682, then the bug no longer exists. Use this configuration as a workaround to solve this bug: This configuration disables the SSR improvements added by #3682
Listing the individual error pages for 403, 404, and 500 will fix the problem for those specific pages. But, a It appears the issue is that the page must go through SSR for the error code to be properly returned. |
I think that’s exactly right, @tdonohue From what I’ve observed, in the current setup, only the routes defined in ssr.paths are processed by the server during SSR. All other routes — including error pages like 404 or 500 — are rendered on the client side. This means it's not possible to set a specific HTTP status code for them. The Angular Client-Side router operates entirely in the user's browser. It intercepts URL changes and renders different components of your Angular application without triggering a full page reload. Since the browser doesn’t allow JavaScript to change the HTTP status code after the page has already loaded, these error pages end up returning a 200 OK, even though they display the correct error page. |
Fixed by #4227. If anyone is encountering this error locally, you have two possible fixes/workarounds:
|
Describe the bug
In DSpace, pages that should return proper HTTP error codes (e.g., 500, 404, or 403) are instead returning a
200 OK
status. This misbehavior affects search engine indexing and SEO, as search engines may incorrectly interpret error pages as valid content.I’ve tested this issue on the DSpace demo site using Firefox and Chrome, and the following URLs all return a
200 OK
status instead of the appropriate error code:This issue has been observed in both DSpace 7.x and DSpace 8.x.
To Reproduce
Steps to reproduce the behavior:
curl -I
)200 OK
, even though the page clearly shows an error messageExpected behavior
The HTTP response should return the correct error status code:
404 Not Found
for missing pages403 Forbidden
for unauthorized access500 Internal Server Error
for internal failuresThis ensures correct behavior for clients and search engines, and improves SEO by preventing incorrect indexing of error pages.
Related work
N/A – please let me know if there's an existing issue or PR related to this.
The text was updated successfully, but these errors were encountered: