SlideShare a Scribd company logo
Ankit Lawaniya
9/3/2017 Ankit Lawaniya 1
 Here we will discuss how to enable Cross-
Origin Request Sharing in Mule by adding
outbound header properties.
9/3/2017 Ankit Lawaniya 2
The same-origin policy is an important security concept implemented
by web browsers to prevent JavaScript from making requests across
domain boundaries (e.g., different domain) than the one from which it
was served. It does not allow interactions between resources from
different origins.
 For example, your JavaScript code hosted at http://domain-a.com
might want to use a REST API hosted at http://domain-b.com.
However, because these are two different origins from the
perspective of the browser, the browser won't allow a script from
http://domain-a.com to fetch resources from http://domain-
b.com, because the resource being fetched is from a different
origin.
9/3/2017 Ankit Lawaniya 3
If the script on your page is running from domain http://domain-
a.com and would like to request a resource which is in another
domain http://domain-b.com, this is a cross-origin request.These
types of request is called Cross-Origin Request, For security reasons
these types of requests have been prohibited by browsers.
9/3/2017 Ankit Lawaniya 4
The solution of above issue is Cross-Origin Resource
Sharing(CORS).CORS introduces a standard mechanism that can be
used by all browsers for implementing cross-domain requests (Cross-
Origin Request), allowing Javascript on a web page to consume a
REST API served from a different origin.
The Cross-Origin Resource Sharing (CORS) mechanism gives web
servers cross-domain access controls, which enable secure cross-
domain data transfers.
9/3/2017 Ankit Lawaniya 5
The Cross-Origin Resource Sharing standard works by adding
new HTTP headers that allow servers to describe the set of
origins that are permitted to read that information using a web
browser. In its simplest form, the requesting application
specifies an Origin header in the request, which describes the
origin of the request, and the requested resource will reply
intern with an Access-Contol-Allow-Origin header indicating
specific origins that are allowed to access a particular resource.
This exchange of headers is what makes CORS a secure
mechanism. The server must support CORS and indicate that
the domain of the client making the request is permitted to do
so. The beauty of this mechanism is that it is automatically
handled by the browser and web application developers do not
need to concern themselves with its details.
9/3/2017 Ankit Lawaniya 6
GET /awesomeapi/list HTTP/1.1
Host: myawesomeapp.com
User-Agent: Mozilla/5.0
Accept: */*
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate
Connection: keep-alive
Origin: http://myawesomeapp.com
9/3/2017 Ankit Lawaniya 7
HTTP/1.1 200 OK
Access-Control-Allow-Origin: http://myapp.com
Content-Type: application/json; charset=utf-8
9/3/2017 Ankit Lawaniya 8
Let’s walk through how to enable CORS in a Mule application.
We need to add the following outbound properties into the flow as
shown below. The following properties are added to accept any
origin, method and headers so that cross origin/domain requests can
be allowed.
<set-property propertyName="Access-Control-Allow-Origin"
value="*" doc:name="Access-Control-Allow-Origin" />
<set-property propertyName="Access-Control-Allow-Headers"
value="*" doc:name="Access-Control-Allow-Headers"/>
<set-property propertyName="Access-Control-Allow-Methods"
value="*" doc:name="Access-Control-Allow-Methods" />
9/3/2017 Ankit Lawaniya 9
9/3/2017 Ankit Lawaniya 10
9/3/2017 Ankit Lawaniya 11
Request:
http://localhost:8081/cors/cors
Below is the screenshot of the response headers as part of the
response.
9/3/2017 Ankit Lawaniya 12
9/3/2017 Ankit Lawaniya 13

More Related Content

PPTX
Uniform Resource Locator (URL)
PPTX
PPT
Web crawler
PDF
Rest web services
PPT
Rest in Rails
PPTX
Rest and Rails
PPTX
Rest & RESTful WebServices
KEY
Rest and the hypermedia constraint
Uniform Resource Locator (URL)
Web crawler
Rest web services
Rest in Rails
Rest and Rails
Rest & RESTful WebServices
Rest and the hypermedia constraint

What's hot (20)

PPT
The RESTful Soa Datagrid with Oracle
PPTX
REST API
PPTX
Rest api-basic
PPT
Working with WebSPHINX Web Crawler
PDF
Smart Crawler Base Paper A two stage crawler for efficiently harvesting deep-...
PPTX
Web server
PPTX
The glory of REST in Java: Spring HATEOAS, RAML, Temenos IRIS
PPTX
Building RESTfull Data Services with WebAPI
PPTX
Smart crawlet A two stage crawler for efficiently harvesting deep web interf...
PPTX
JSON and REST
PDF
Api design and development
PPTX
Introductiontowebarchitecture 090922221506-phpapp01
PPTX
Overview of RESTful web services
PDF
REST - Representational State Transfer
PDF
Intro webapps
PPTX
REST & RESTful Web Services
PPT
Working of a Web Crawler
PPTX
Spring HATEOAS
PPTX
RESTful Architecture
PPTX
Implementation advantages of rest
The RESTful Soa Datagrid with Oracle
REST API
Rest api-basic
Working with WebSPHINX Web Crawler
Smart Crawler Base Paper A two stage crawler for efficiently harvesting deep-...
Web server
The glory of REST in Java: Spring HATEOAS, RAML, Temenos IRIS
Building RESTfull Data Services with WebAPI
Smart crawlet A two stage crawler for efficiently harvesting deep web interf...
JSON and REST
Api design and development
Introductiontowebarchitecture 090922221506-phpapp01
Overview of RESTful web services
REST - Representational State Transfer
Intro webapps
REST & RESTful Web Services
Working of a Web Crawler
Spring HATEOAS
RESTful Architecture
Implementation advantages of rest
Ad

Similar to Cors (cross origin request sharing) in mule (20)

PPTX
Mule meetup 25thjan
PDF
Cors michael
PPTX
Cross Origin Resource Sharing (CORS) - Azizul Hakim
PDF
Web 13 | REST API
PDF
JavaScript Security: Mastering Cross Domain Communications in complex JS appl...
PDF
What Is Cross-Origin Resource Sharing in Web Development.pdf
PDF
CORS in Action Creating and consuming cross origin APIs 1st Edition Monsur Ho...
PDF
Cross site calls with javascript - the right way with CORS
PPTX
Cross-origin resource sharing
PDF
Cross-domain requests with CORS
PPTX
Conquering CORS. Taming Cross-Origin Resource Sharing.
PDF
RefCard RESTful API Design
PDF
Cors
PDF
CORS and (in)security
PPTX
Web api 2 With MVC 5 With TrainerKrunal
PPTX
Of CORS thats a thing how CORS in the cloud still kills security
PPTX
CORS - Enable Alfresco for CORS
PPTX
Web Security - Cookies, Domains and CORS
PDF
Cors kung fu
PPTX
Restful api
Mule meetup 25thjan
Cors michael
Cross Origin Resource Sharing (CORS) - Azizul Hakim
Web 13 | REST API
JavaScript Security: Mastering Cross Domain Communications in complex JS appl...
What Is Cross-Origin Resource Sharing in Web Development.pdf
CORS in Action Creating and consuming cross origin APIs 1st Edition Monsur Ho...
Cross site calls with javascript - the right way with CORS
Cross-origin resource sharing
Cross-domain requests with CORS
Conquering CORS. Taming Cross-Origin Resource Sharing.
RefCard RESTful API Design
Cors
CORS and (in)security
Web api 2 With MVC 5 With TrainerKrunal
Of CORS thats a thing how CORS in the cloud still kills security
CORS - Enable Alfresco for CORS
Web Security - Cookies, Domains and CORS
Cors kung fu
Restful api
Ad

More from Ankit Lawaniya (12)

PPTX
Content based routing using mule choice flow control
PPTX
Until successful scope in mule
PPTX
First successful-router
PPTX
Iterative processing using the for each scope in
PPTX
Improving performance with cache scope in mule
PPTX
Content enrichment using mule message enricher
PPTX
Validation module in mule
PPTX
Schema validation filter (xml schema validation)
PPTX
Validate json schema component
PPTX
Parse template transformer mule
PPTX
Active mq read and write flow in mule
PPTX
Composite source in mule
Content based routing using mule choice flow control
Until successful scope in mule
First successful-router
Iterative processing using the for each scope in
Improving performance with cache scope in mule
Content enrichment using mule message enricher
Validation module in mule
Schema validation filter (xml schema validation)
Validate json schema component
Parse template transformer mule
Active mq read and write flow in mule
Composite source in mule

Recently uploaded (20)

PDF
cuic standard and advanced reporting.pdf
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PDF
Video forgery: An extensive analysis of inter-and intra-frame manipulation al...
PDF
NewMind AI Weekly Chronicles - August'25-Week II
PDF
Encapsulation theory and applications.pdf
PPTX
Big Data Technologies - Introduction.pptx
PDF
Machine learning based COVID-19 study performance prediction
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PDF
MIND Revenue Release Quarter 2 2025 Press Release
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PPTX
Machine Learning_overview_presentation.pptx
PPT
Teaching material agriculture food technology
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PDF
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
PDF
Electronic commerce courselecture one. Pdf
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PPTX
SOPHOS-XG Firewall Administrator PPT.pptx
PPTX
Spectroscopy.pptx food analysis technology
PPTX
MYSQL Presentation for SQL database connectivity
PDF
A comparative analysis of optical character recognition models for extracting...
cuic standard and advanced reporting.pdf
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
Video forgery: An extensive analysis of inter-and intra-frame manipulation al...
NewMind AI Weekly Chronicles - August'25-Week II
Encapsulation theory and applications.pdf
Big Data Technologies - Introduction.pptx
Machine learning based COVID-19 study performance prediction
Mobile App Security Testing_ A Comprehensive Guide.pdf
MIND Revenue Release Quarter 2 2025 Press Release
Digital-Transformation-Roadmap-for-Companies.pptx
Machine Learning_overview_presentation.pptx
Teaching material agriculture food technology
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
Electronic commerce courselecture one. Pdf
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
SOPHOS-XG Firewall Administrator PPT.pptx
Spectroscopy.pptx food analysis technology
MYSQL Presentation for SQL database connectivity
A comparative analysis of optical character recognition models for extracting...

Cors (cross origin request sharing) in mule

  • 2.  Here we will discuss how to enable Cross- Origin Request Sharing in Mule by adding outbound header properties. 9/3/2017 Ankit Lawaniya 2
  • 3. The same-origin policy is an important security concept implemented by web browsers to prevent JavaScript from making requests across domain boundaries (e.g., different domain) than the one from which it was served. It does not allow interactions between resources from different origins.  For example, your JavaScript code hosted at http://domain-a.com might want to use a REST API hosted at http://domain-b.com. However, because these are two different origins from the perspective of the browser, the browser won't allow a script from http://domain-a.com to fetch resources from http://domain- b.com, because the resource being fetched is from a different origin. 9/3/2017 Ankit Lawaniya 3
  • 4. If the script on your page is running from domain http://domain- a.com and would like to request a resource which is in another domain http://domain-b.com, this is a cross-origin request.These types of request is called Cross-Origin Request, For security reasons these types of requests have been prohibited by browsers. 9/3/2017 Ankit Lawaniya 4
  • 5. The solution of above issue is Cross-Origin Resource Sharing(CORS).CORS introduces a standard mechanism that can be used by all browsers for implementing cross-domain requests (Cross- Origin Request), allowing Javascript on a web page to consume a REST API served from a different origin. The Cross-Origin Resource Sharing (CORS) mechanism gives web servers cross-domain access controls, which enable secure cross- domain data transfers. 9/3/2017 Ankit Lawaniya 5
  • 6. The Cross-Origin Resource Sharing standard works by adding new HTTP headers that allow servers to describe the set of origins that are permitted to read that information using a web browser. In its simplest form, the requesting application specifies an Origin header in the request, which describes the origin of the request, and the requested resource will reply intern with an Access-Contol-Allow-Origin header indicating specific origins that are allowed to access a particular resource. This exchange of headers is what makes CORS a secure mechanism. The server must support CORS and indicate that the domain of the client making the request is permitted to do so. The beauty of this mechanism is that it is automatically handled by the browser and web application developers do not need to concern themselves with its details. 9/3/2017 Ankit Lawaniya 6
  • 7. GET /awesomeapi/list HTTP/1.1 Host: myawesomeapp.com User-Agent: Mozilla/5.0 Accept: */* Accept-Language: en-US,en;q=0.5 Accept-Encoding: gzip, deflate Connection: keep-alive Origin: http://myawesomeapp.com 9/3/2017 Ankit Lawaniya 7
  • 8. HTTP/1.1 200 OK Access-Control-Allow-Origin: http://myapp.com Content-Type: application/json; charset=utf-8 9/3/2017 Ankit Lawaniya 8
  • 9. Let’s walk through how to enable CORS in a Mule application. We need to add the following outbound properties into the flow as shown below. The following properties are added to accept any origin, method and headers so that cross origin/domain requests can be allowed. <set-property propertyName="Access-Control-Allow-Origin" value="*" doc:name="Access-Control-Allow-Origin" /> <set-property propertyName="Access-Control-Allow-Headers" value="*" doc:name="Access-Control-Allow-Headers"/> <set-property propertyName="Access-Control-Allow-Methods" value="*" doc:name="Access-Control-Allow-Methods" /> 9/3/2017 Ankit Lawaniya 9
  • 12. Request: http://localhost:8081/cors/cors Below is the screenshot of the response headers as part of the response. 9/3/2017 Ankit Lawaniya 12