Skip to content

SharedSecretAuthenticationProvider returns 500 instead of 401 for auth failures #1421

@michaellwest

Description

@michaellwest

Summary

SPE's remoting endpoint (/-/script/script/) returns HTTP 500 for authentication failures that should return 401. This makes it difficult for clients to distinguish auth configuration problems from genuine server errors.

Observed Behavior

Scenario Actual Status Expected Status
No auth header 401 401 ✓
Wrong shared secret 500 401
Wrong JWT audience 500 401
Valid auth, server error 500 500 ✓

When SharedSecretAuthenticationProvider fails to validate the HMAC signature or JWT audience, the exception appears to bubble up unhandled, causing IIS/Sitecore to return a generic 500 rather than a proper 401 Unauthorized.

Impact

  • MCP clients (and any remoting consumer) cannot programmatically distinguish "your secret is wrong" from "the server crashed"
  • Troubleshooting auth issues requires checking Sitecore server logs instead of the HTTP response
  • Automated health checks and connection tests cannot provide targeted diagnostic hints

Suggested Fix

In SharedSecretAuthenticationProvider, catch signature/audience validation failures and return a 401 response with a descriptive message instead of letting the exception propagate. For example:

// Instead of throwing on validation failure:
if (!ValidateSignature(token, secret))
{
    context.Response.StatusCode = 401;
    context.Response.StatusDescription = "JWT signature validation failed";
    context.Response.End();
    return;
}

Environment

  • SPE remoting tested against Sitecore 10.4.1
  • Auth type: SharedSecret (HS256 JWT)
  • Tested via the SPE MCP Server

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions