All Products
Search
Document Center

Object Storage Service:cors (cross-origin resource sharing)

Last Updated:Aug 28, 2026

Cross-origin resource sharing (CORS) is a standard HTML5 mechanism that allows web application servers to control cross-origin access. This ensures the security of data transmission across different origins. This topic describes how to use the cors command to add, modify, query, and delete a bucket's CORS configuration.

Usage notes

  • To add or modify a CORS configuration, you must have the oss:PutBucketCors permission. To retrieve a CORS configuration, you must have the oss:GetBucketCors permission. To delete a CORS configuration, you must have the oss:DeleteBucketCors permission. For more information, see Grant custom permissions to a RAM user.

  • Starting from ossutil 1.6.16, you can use ossutil as the binary name in the command line regardless of your operating system. If you use a version of ossutil earlier than 1.6.16, you must change the binary name based on your operating system. For more information, see ossutil command reference.

  • For more information about CORS, see Cross-origin resource sharing.

Add or modify a CORS configuration

If the bucket does not have a CORS configuration, this command adds one. If the bucket already has a CORS configuration, this command overwrites it.

To add or modify a CORS configuration, follow these steps:

  1. Create a local file and add CORS rules to the file.

  2. ossutil reads the CORS configuration from the local file and applies it to the specified bucket.

The command format and an example are as follows:

  • Command format

    ossutil cors --method put oss://bucketname local_xml_file

    The parameters are as follows:

    Parameter

    Description

    bucketname

    The name of the bucket for which you want to add or modify the CORS configuration.

    local_xml_file

    The name of the local file that contains the CORS rules. For example, localfile.txt.

  • Example

    1. Create a local file named localfile.txt and add the required CORS rules to the file.

      The following sample CORS rule allows cross-origin PUT requests from http://www.aliyun.com. It also specifies that the browser caches the response to a preflight (OPTIONS) request for a specific resource for 10,000 seconds.

      <?xml version="1.0" encoding="UTF-8"?>
         <CORSConfiguration>
           <CORSRule>
               <AllowedOrigin>http://www.aliyun.com</AllowedOrigin>
               <AllowedMethod>PUT</AllowedMethod>
               <MaxAgeSeconds>10000</MaxAgeSeconds>
           </CORSRule>
       </CORSConfiguration>
    2. Add a CORS rule for the examplebucket bucket.

      ossutil cors --method put oss://examplebucket localfile.txt

      The following output indicates that the CORS rule is added.

      0.299514(s) elapsed

Get a CORS configuration

  • Command format

    ossutil cors --method get oss://bucketname [local_xml_file]

    The parameters are as follows:

    Parameter

    Description

    bucketname

    The name of the bucket whose CORS configuration you want to get.

    local_xml_file

    The name of the local file to which you want to save the CORS configuration. For example, localfile.txt. If you do not specify this parameter, the CORS configuration is printed to the screen.

  • Example

    Retrieve the CORS configuration for the examplebucket bucket.

    ossutil cors --method get oss://examplebucket localfile.txt

    The following output indicates that the CORS configuration is retrieved and written to the localfile.txt file.

    0.212407(s) elapsed

Delete a CORS configuration

  • Command format

    ossutil cors --method delete oss://bucketname
  • Example

    Delete the CORS configuration from the examplebucket bucket.

    ossutil cors --method delete oss://examplebucket

    The following output indicates that the CORS configuration for the examplebucket bucket is deleted.

    0.530750(s) elapsed

Common options

To access a bucket in a different region, use -e to specify the endpoint. To access a bucket owned by a different Alibaba Cloud account, use -i for the AccessKey ID and -k for the AccessKey secret.

For example, to add a CORS configuration to a bucket named testbucket that is in the China (Hangzhou) region and owned by another Alibaba Cloud account, run the following command:

ossutil cors --method put oss://testbucket localfile.txt -e oss-cn-hangzhou.aliyuncs.com -i yourAccessKeyID -k yourAccessKeySecret

Common options.