Compute
Elastic Cloud Server
Huawei Cloud Flexus
Bare Metal Server
Auto Scaling
Image Management Service
Dedicated Host
FunctionGraph
Cloud Phone Host
Huawei Cloud EulerOS
Networking
Virtual Private Cloud
Elastic IP
Elastic Load Balance
NAT Gateway
Direct Connect
Virtual Private Network
VPC Endpoint
Cloud Connect
Enterprise Router
Enterprise Switch
Global Accelerator
Management & Governance
Cloud Eye
Identity and Access Management
Cloud Trace Service
Resource Formation Service
Tag Management Service
Log Tank Service
Config
OneAccess
Resource Access Manager
Simple Message Notification
Application Performance Management
Application Operations Management
Organizations
Optimization Advisor
IAM Identity Center
Cloud Operations Center
Resource Governance Center
Migration
Server Migration Service
Object Storage Migration Service
Cloud Data Migration
Migration Center
Cloud Ecosystem
KooGallery
Partner Center
User Support
My Account
Billing Center
Cost Center
Resource Center
Enterprise Management
Service Tickets
HUAWEI CLOUD (International) FAQs
ICP Filing
Support Plans
My Credentials
Customer Operation Capabilities
Partner Support Plans
Professional Services
Analytics
MapReduce Service
Data Lake Insight
CloudTable Service
Cloud Search Service
Data Lake Visualization
Data Ingestion Service
GaussDB(DWS)
DataArts Studio
Data Lake Factory
DataArts Lake Formation
IoT
IoT Device Access
Others
Product Pricing Details
System Permissions
Console Quick Start
Common FAQs
Instructions for Associating with a HUAWEI CLOUD Partner
Message Center
Security & Compliance
Security Technologies and Applications
Web Application Firewall
Host Security Service
Cloud Firewall
SecMaster
Anti-DDoS Service
Data Encryption Workshop
Database Security Service
Cloud Bastion Host
Data Security Center
Cloud Certificate Manager
Edge Security
Situation Awareness
Managed Threat Detection
Blockchain
Blockchain Service
Web3 Node Engine Service
Media Services
Media Processing Center
Video On Demand
Live
SparkRTC
MetaStudio
Storage
Object Storage Service
Elastic Volume Service
Cloud Backup and Recovery
Storage Disaster Recovery Service
Scalable File Service Turbo
Scalable File Service
Volume Backup Service
Cloud Server Backup Service
Data Express Service
Dedicated Distributed Storage Service
Containers
Cloud Container Engine
SoftWare Repository for Container
Application Service Mesh
Ubiquitous Cloud Native Service
Cloud Container Instance
Databases
Relational Database Service
Document Database Service
Data Admin Service
Data Replication Service
GeminiDB
GaussDB
Distributed Database Middleware
Database and Application Migration UGO
TaurusDB
Middleware
Distributed Cache Service
API Gateway
Distributed Message Service for Kafka
Distributed Message Service for RabbitMQ
Distributed Message Service for RocketMQ
Cloud Service Engine
Multi-Site High Availability Service
EventGrid
Dedicated Cloud
Dedicated Computing Cluster
Business Applications
Workspace
ROMA Connect
Message & SMS
Domain Name Service
Edge Data Center Management
Meeting
AI
Face Recognition Service
Graph Engine Service
Content Moderation
Image Recognition
Optical Character Recognition
ModelArts
ImageSearch
Conversational Bot Service
Speech Interaction Service
Huawei HiLens
Video Intelligent Analysis Service
Developer Tools
SDK Developer Guide
API Request Signing Guide
Terraform
Koo Command Line Interface
Content Delivery & Edge Computing
Content Delivery Network
Intelligent EdgeFabric
CloudPond
Intelligent EdgeCloud
Solutions
SAP Cloud
High Performance Computing
Developer Services
ServiceStage
CodeArts
CodeArts PerfTest
CodeArts Req
CodeArts Pipeline
CodeArts Build
CodeArts Deploy
CodeArts Artifact
CodeArts TestPlan
CodeArts Check
CodeArts Repo
Cloud Application Engine
MacroVerse aPaaS
KooMessage
KooPhone
KooDrive
Help Center/ Object Storage Service/ User Guide/ Data Security/ Configuring CORS to Allow Cross-Origin Access to OBS

Configuring CORS to Allow Cross-Origin Access to OBS

Updated on 2024-11-05 GMT+08:00

This section describes how to use CORS in HTML5 to enable cross-origin access.

You can create CORS rules or replicate existing CORS rules from another bucket.

Context

Cross-origin access refers to access between different domains.

For browser security purposes, cross-origin access is typically restricted by the same-origin policy. Under this policy, resources in a domain cannot be accessed by a different domain using JavaScript.

If two web pages have the same protocol, domain name or IP, and port (if specified), they have the same origin. Table 1 shows you how to determine whether the URLs listed in the table have the same origin as https://support.huaweicloud.com/dir/test.html.

Table 1 Cross-origin analysis

URL

Access Result

Reason

https://support.huaweicloud.com/dir/other.html

Succeeded

Same protocol, domain name, and port

https://support.huaweicloud.com/dir/inner/other.html

Succeeded

Same protocol, domain name, and port

http://support.huaweicloud.com/dir/test.html

Failed

Same domain name and port, but different protocols

https://support.huaweicloud.com:81/dir/test.html

Failed

Same protocol and domain name, but different ports

https://help.huaweicloud.com/dir/test.html

Failed

Same protocol and port, but different domain names

Scenarios

CORS (cross-origin resource sharing) is a browser-standard mechanism provided by the World Wide Web Consortium (W3C). It defines how a web client in one origin interacts with resources in another origin. For general web page requests, website scripts and contents in one origin cannot interact with those in another origin because of Same Origin Policies (SOPs).

OBS supports CORS. OBS resources can be accessed across origins.

OBS supports static website hosting. Static websites stored in OBS can respond to website requests from another origin only when CORS is configured for the bucket where the website files are stored.

CORS:
  • Enables you to access OBS resources without using a proxy when using JavaScript and HTML5 to develop web applications.
  • Enables you to directly upload files to OBS with the dragging function of HTML5, view the progress, or update contents directly from web applications.
  • Enables external web pages, style sheets, or HTML5 applications hosted in different origins to share web fonts or images stored in OBS.

The CORS configuration takes about two minutes to take effect.

NOTICE:

OBS is configured to support cross-origin access using the root domain name by default. To prevent potential attacks:

You can create a crossdomain.xml file with specific rules in the bucket for your client and add then Security.loadPolicyFile("https://bucket.obs.ap-southeast-1.myhuaweicloud.com/crossdomain.xml") in the flash code of the file. bucket.obs.ap-southeast-1.myhuaweicloud.com needs to be replaced with the actual access domain name of your bucket.

Prerequisites

Static website hosting has been configured. For details, see Static Website Hosting.

Creating a CORS Rule

You can use OBS Console, APIs, or SDKs to create CORS rules.

Replicating CORS Rules

You can only use OBS Console to replicate CORS rules.

  1. In the navigation pane of OBS Console, choose Object Storage.
  2. In the bucket list, click the bucket you want to operate. The Objects page is displayed.
  3. In the navigation pane, choose Overview.
  4. In the Basic Configurations area, click CORS Rules. The CORS Rules page is displayed.

    Alternatively, you can choose Permissions > CORS Rules in the navigation pane.

  5. Click Replicate.
  6. Select a replication source, which is the bucket whose CORS rules you want to replicate.

    NOTE:
    • The CORS rules replicated from a source bucket will not overwrite existing rules in the destination bucket, and any that conflict with the existing ones will not be replicated.
    • Both source and destination buckets must be of the 3.0 version.
    • You can remove the rules that you do not want to replicate.
    • There can be 100 CORS rules at most in a bucket. If the number of rules you will replicate plus the number of existing rules in the destination bucket exceeds 100, the replication will fail. Before replicating the rules, delete some if necessary.
    Figure 2 Replicating CORS rules

  7. Click OK to replicate the CORS rules to the destination bucket.

We use cookies to improve our site and your experience. By continuing to browse our site you accept our cookie policy. Find out more

Feedback

Feedback

Feedback

0/500

Selected Content

Submit selected content with the feedback