Skip to content

Commit 2ed4cf3

Browse files
committed
fix: Configure CORS correctly
1 parent a7666ba commit 2ed4cf3

File tree

3 files changed

+14
-21
lines changed

3 files changed

+14
-21
lines changed

configuration.example.toml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,8 @@ contributors-repositories = [
1010
"revanced-manager",
1111
]
1212
api-version = 1
13-
cors = { host = "*.revanced.app", sub-domains = [] }
14-
endpoint = "https://api.revanced.app"
13+
cors-allowed-hosts = [
14+
"revanced.app",
15+
"*.revanced.app"
16+
]
17+
endpoint = "https://api.revanced.app"

src/main/kotlin/app/revanced/api/configuration/HTTP.kt

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,12 @@ fun Application.configureHTTP() {
1313
val configurationRepository = get<ConfigurationRepository>()
1414

1515
install(CORS) {
16-
allowHost(
17-
host = configurationRepository.cors.host,
18-
subDomains = configurationRepository.cors.subDomains,
19-
)
16+
configurationRepository.corsAllowedHosts.forEach { host ->
17+
allowHost(
18+
host = host,
19+
schemes = listOf("http", "https")
20+
)
21+
}
2022
}
2123

2224
install(RateLimit) {

src/main/kotlin/app/revanced/api/configuration/repository/ConfigurationRepository.kt

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import java.io.File
1919
* @property integrations The source of the integrations.
2020
* @property contributorsRepositoryNames The names of the repositories to get contributors from.
2121
* @property apiVersion The version to use for the API.
22-
* @property cors The CORS configuration.
22+
* @property corsAllowedHosts The hosts allowed to make requests to the API.
2323
* @property endpoint The endpoint of the API.
2424
*/
2525
@Serializable
@@ -31,7 +31,8 @@ internal class ConfigurationRepository(
3131
val contributorsRepositoryNames: Set<String>,
3232
@SerialName("api-version")
3333
val apiVersion: Int = 1,
34-
val cors: Cors,
34+
@SerialName("cors-allowed-hosts")
35+
val corsAllowedHosts: Set<String>,
3536
val endpoint: String,
3637
) {
3738
/**
@@ -61,19 +62,6 @@ internal class ConfigurationRepository(
6162
@SerialName("public-key-file")
6263
val publicKeyFile: File,
6364
)
64-
65-
/**
66-
* The CORS configuration.
67-
*
68-
* @property host The host of the API to configure CORS.
69-
* @property subDomains The subdomains to allow for CORS.
70-
*/
71-
@Serializable
72-
internal class Cors(
73-
val host: String,
74-
@SerialName("sub-domains")
75-
val subDomains: List<String>,
76-
)
7765
}
7866

7967
private object RegexSerializer : KSerializer<Regex> {

0 commit comments

Comments
 (0)