Score:3

Why are CSRF Tokens not required on these REST Web Services endpoints?

br flag

I am using the miniOrange API Authentication module to handle API Key Authorization for my custom Rest Endpoints built by extending the REST Web Services module.

I notice that my POST and PATCH methods work perfectly fine without a CSRF token provided by the /session/token endpoint. Does API Key Authorization remove the need for CSRF tokens or why am I able to make successful POST/PATCH requests without a CSRF Token? I thought they were required...

/**
 * Provides a My Resource
 * 
 * @RestResource(
 *  id = "my_resource",
 *  label = @Translation("My Resource"),
 *  uri_paths = {
 *    "canonical" = "/my_api/test",
 *    "create" = "/my_api/test"
 *  }
 * )
 */
class MyResource extends ResourceBase {

  /**
   * Responds to GET requests.
   * @return \Drupal\rest\ResourceResponse
   */
  public function get() {
    $response = ['message' => 'This GET endpoint still needs to be implemented'];
    return new ResourceResponse($response);
  }

  /**
   * Responds to POST requests.
   * @return \Drupal\rest\ResourceResponse
   */
  public function post() {
    $response = ['message' => 'This POST endpoint still needs to be implemented'];
    return new ResourceResponse($response);
  }

  /**
   * Responds to PATCH requests.
   * @return \Drupal\rest\ResourceResponse
   */
  public function patch() {
    $response = ['message' => 'This PATCH endpoint still needs to be implemented'];
    return new ResourceResponse($response);
  }

No Sssweat avatar
ua flag
What is the path/url that you're posting those PATCH and POST requests?
BlondeSwan avatar
br flag
it's a custom path for a custom API Resource. In this example, the path is /my_api/test as described in the class signature
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.