Research
Security News
Malicious npm Package Targets Solana Developers and Hijacks Funds
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
ch.megard:akka-http-cors_3
Advanced tools
CORS (Cross Origin Resource Sharing) is a mechanism to enable cross origin requests.
This is a Scala/Java implementation for the server-side targeting the akka-http library.
Version | Release date | Akka Http version | Scala versions |
---|---|---|---|
1.2.0 | 2023-03-04 | 10.2.10 | 2.12.17 , 2.13.10 , 3.2.2 |
1.1.3 | 2022-01-30 | 10.2.7 | 2.12.15 , 2.13.8 , 3.1.1 |
1.0.0 | 2020-05-25 | 10.1.12 | 2.12.11 , 2.13.2 |
0.1.0 | 2016-03-20 | 2.4.2 | 2.11.8 |
Some less interesting versions are not listed in the above table. The complete list can be found in the CHANGELOG file.
akka-http-cors is deployed to Maven Central. Add it to your build.sbt
or Build.scala
:
libraryDependencies += "ch.megard" %% "akka-http-cors" % "1.2.0"
The simplest way to enable CORS in your application is to use the cors
directive.
Settings are passed as a parameter to the directive, with your overrides loaded from the application.conf
.
import ch.megard.akka.http.cors.scaladsl.CorsDirectives._
val route: Route = cors() {
complete(...)
}
The settings can be updated programmatically too.
val settings = CorsSettings(...).withAllowGenericHttpRequests(false)
val strictRoute: Route = cors(settings) {
complete(...)
}
A full example, with proper exception and rejection handling, is available in the akka-http-cors-example
sub-project.
The CORS directives can reject requests using the CorsRejection
class. Requests can be either malformed or not allowed to access the resource.
A rejection handler is provided by the library to return meaningful HTTP responses. Read the akka documentation to learn more about rejections, or if you need to write your own handler.
import akka.http.scaladsl.server.directives.ExecutionDirectives._
import ch.megard.akka.http.cors.scaladsl.CorsDirectives._
val route: Route = handleRejections(corsRejectionHandler) {
cors() {
complete(...)
}
}
Starting from version 0.2.1
Java is supported, mirroring the Scala API. For usage, look at the full Java CorsServer example.
Boolean
with default value true
.
If true
, allow generic requests (that are outside the scope of the specification) to pass through the directive. Else, strict CORS filtering is applied and any invalid request will be rejected.
Boolean
with default value true
.
Indicates whether the resource supports user credentials. If true
, the header Access-Control-Allow-Credentials
is set in the response, indicating the actual request can include user credentials.
Examples of user credentials are: cookies, HTTP authentication or client-side certificates.
HttpOriginMatcher
with default value HttpOriginMatcher.*
.
List of origins that the CORS filter must allow. Can also be set to *
to allow access to the resource from any origin. Controls the content of the Access-Control-Allow-Origin
response header:
*
and credentials are not allowed, a *
is set in Access-Control-Allow-Origin
.Origin
request header are echoed.Hostname starting with *.
will match any sub-domain. The scheme and the port are always strictly matched.
The actual or preflight request is rejected if any of the origins from the request is not allowed.
HttpHeaderRange
with default value HttpHeaderRange.*
.
List of request headers that can be used when making an actual request. Controls the content of the Access-Control-Allow-Headers
header in a preflight response:
*
, the headers from Access-Control-Request-Headers
are echoed.Seq[HttpMethod]
with default value Seq(GET, POST, HEAD, OPTIONS)
.
List of methods that can be used when making an actual request. The list is returned as part of the Access-Control-Allow-Methods
preflight response header.
The preflight request will be rejected if the Access-Control-Request-Method
header's method is not part of the list.
Seq[String]
with default value Seq.empty
.
List of headers (other than simple response headers) that browsers are allowed to access. If not empty, this list is returned as part of the Access-Control-Expose-Headers
header in the actual response.
Option[Long]
(in seconds) with default value Some (30 * 60)
.
When set, the amount of seconds the browser is allowed to cache the results of a preflight request. This value is returned as part of the Access-Control-Max-Age
preflight response header. If None
, the header is not added to the preflight response.
Using the sbt-jmh plugin, preliminary benchmarks have been performed to measure the impact of the cors
directive on the performance. The first results are shown below.
Results are not all coming from the same machine.
> jmh:run -i 40 -wi 30 -f2 -t1
Benchmark Mode Cnt Score Error Units
CorsBenchmark.baseline thrpt 80 3601.121 ± 102.274 ops/s
CorsBenchmark.default_cors thrpt 80 3582.090 ± 95.304 ops/s
CorsBenchmark.default_preflight thrpt 80 3482.716 ± 89.124 ops/s
> jmh:run -i 40 -wi 30 -f2 -t1
Benchmark Mode Cnt Score Error Units
CorsBenchmark.baseline thrpt 80 3657.762 ± 141.409 ops/s
CorsBenchmark.default_cors thrpt 80 3687.351 ± 35.176 ops/s
CorsBenchmark.default_preflight thrpt 80 3645.629 ± 30.411 ops/s
> jmh:run -i 40 -wi 30 -f2 -t1
Benchmark Mode Cnt Score Error Units
CorsBenchmark.baseline thrpt 80 9730.001 ± 25.281 ops/s
CorsBenchmark.default_cors thrpt 80 9159.320 ± 25.459 ops/s
CorsBenchmark.default_preflight thrpt 80 9172.938 ± 26.794 ops/s
This code is open source software licensed under the Apache 2.0 License.
FAQs
akka-http-cors
We found that ch.megard:akka-http-cors_3 demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
Security News
Research
Socket researchers have discovered malicious npm packages targeting crypto developers, stealing credentials and wallet data using spyware delivered through typosquats of popular cryptographic libraries.
Security News
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.