r/apify • • 22h ago

Help needed Multi-tenant Server Actors: How to securely distinguish authenticated gateway requests from direct container access?

Hi everyone,

We're developing a new Actor that supports both regular Runs and the multi-tenant Server interface, using pay-per-event (PPE) billing.

During private cloud testing, we encountered a security question that we haven't been able to resolve through the official documentation.

What we've observed

  • The authenticated Server gateway validates the caller's Apify token and provides X-Apify-User-ID and X-Actor-Request-ID.
  • Anonymous requests to the Server gateway are rejected.
  • However, the direct container URL (*.runs.apify.net) appears to be accessible without authentication.
  • Requests sent directly to the container can include client-supplied values for those same identity headers.

This makes it difficult for our application to determine whether a request actually came through the authenticated Apify gateway.

Why this matters

We understand that the Charge API validates the request ID and rejects invalid or expired IDs without charging the customer.

However, by the time our Actor attempts to charge, it may already have consumed compute resources, performed scraping, or called paid third-party APIs.

We would like to verify that a request is legitimate before starting any potentially expensive business processing, rather than relying solely on billing validation afterward.

Our questions

  1. Is there a supported way to disable or restrict direct container access for multi-tenant Server Actors?
  2. Does Apify provide a trusted ingress indicator, signed header, or network-level mechanism that distinguishes authenticated gateway requests from direct container requests?
  3. Is there a read-only API or SDK method to validate an active X-Actor-Request-ID and its associated user identity before charging?
  4. If none of these mechanisms exists, what is the recommended architecture for protecting multi-tenant PPE Server Actors against unauthorized requests that consume compute or paid API resources?

We've reviewed the following documentation:

We've also contacted Apify Support, but their AI assistant confirmed that the public documentation does not provide definitive answers to these questions.

Has anyone encountered this issue when developing a multi-tenant Server Actor? How are you handling trusted request identity in production?

Any insights from experienced Actor developers or the Apify engineering team would be greatly appreciated.

Thanks!

1 Upvotes

2 comments sorted by

2

u/fab_brno 16h ago

Responses from my colleague:

  1. Disabling the container URL: Every run gets a container URL, and there is currently no setting to turn it off for Server Actor runs. The URL contains a random run key and is visible only to the account that owns the run (for multi-tenant, that’s you, the developer), so it isn’t guessable, Don’t log ACTOR_WEB_SERVER_URL, don’t echo request headers back, and don’t expose run objects from your Actor.
  2. Trusted ingress indicator. We don’t have this today. The gateway sets X-Apify-User-ID and X-Actor-Request-ID after validating the token and overrides any copies the caller sent, so those headers are genuine for requests that came through the gateway. There is no signed header or network-level marker that lets your code prove a request took that path. We will consider adding it.
  3. Read-only validation. No separate endpoint exists. But the charge endpoint itself is the validator. Request IDs are random, exist only in platform state while the gateway request is open, and are bound to your Actor and pool. A charge with a fabricated, expired, or foreign ID returns 400 and bills nothing.
  4. Recommended architecture: charge first, then do the work. Move the charge to the top of your handler. This works in all three pools: a paying user is charged, a free user “pays” $0, and your own requests only update stats, but in every case the platform confirms the ID is live and belongs to your Actor. Always charge before you send the response, since the ID stops working when the response closes.

1

u/ClimateDistinct8980 12h ago edited 12h ago

Thank you for the detailed explanation. This has been very helpful.

We have a few follow-up concerns about using the Charge API as a request validation mechanism.

Our Actor provides TikTok video data through a multi-tenant Server Actor. We intend to charge users only when data is successfully retrieved. Charging before processing could result in users being charged for failed requests.

We considered defining a $0 PPE event to validate the request ID before processing, followed by a regular paid event after successful data retrieval. However, we are concerned that this approach would:

  • Double the number of Charge API calls for successful requests.
  • Introduce additional latency, platform resource usage, and potential rate-limit issues.
  • Generate unnecessary billing events without additional commission revenue for Apify.
  • Depend on the billing API for a purpose it may not have been designed to serve.

Could you please clarify the following?

  1. Is there an officially supported way to validate a Server Actor request ID without creating a charge event?
  2. Does Apify officially support $0 PPE events for this purpose, and would you recommend this approach in production?
  3. Does the Charge API have any documented latency expectations, rate limits, or additional platform usage implications?
  4. Does successful request ID validation also establish that the X-Apify-User-ID header belongs to the same authenticated user?
  5. What is Apify's recommended production architecture for preventing unauthorized direct container requests while charging users only after successful processing?

We would prefer to follow an officially supported solution rather than introduce a workaround that could create unnecessary overhead for both Apify and Actor developers.

Thanks again for your help.