Skip to content

Commit

Permalink
allow all origins if input array has wildcard character (#234)
Browse files Browse the repository at this point in the history
* allow all origins if input array has wildcard character

* extracted variable

---------

Co-authored-by: tanghel <[email protected]>
  • Loading branch information
bogdan-rosianu and tanghel authored Sep 30, 2024
1 parent 2a50cff commit 93c9450
Show file tree
Hide file tree
Showing 11 changed files with 28 additions and 19 deletions.
2 changes: 1 addition & 1 deletion lerna.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"$schema": "node_modules/lerna/schemas/lerna-schema.json",
"useWorkspaces": true,
"version": "3.7.7",
"version": "3.7.8",
"packages": [
"packages/*"
],
Expand Down
16 changes: 8 additions & 8 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/auth/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@multiversx/sdk-nestjs-auth",
"version": "3.7.7",
"version": "3.7.8",
"description": "Multiversx SDK Nestjs auth package",
"main": "lib/index.js",
"types": "lib/index.d.ts",
Expand Down
13 changes: 11 additions & 2 deletions packages/auth/src/native.auth.guard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { DecoratorUtils, ErdnestConfigService, ERDNEST_CONFIG_SERVICE, UrlUtils,
import { PerformanceProfiler } from '@multiversx/sdk-nestjs-monitoring';
import { NativeAuthInvalidOriginError } from './errors/native.auth.invalid.origin.error';
import { NoAuthOptions } from './decorators';
import { NativeAuthServerConfig } from "@multiversx/sdk-native-auth-server/lib/src/entities/native.auth.server.config";

/**
* This Guard protects all routes that do not have the `@NoAuth` decorator and sets the `X-Native-Auth-*` HTTP headers.
Expand All @@ -19,7 +20,7 @@ export class NativeAuthGuard implements CanActivate {
@Inject(ERDNEST_CONFIG_SERVICE) erdnestConfigService: ErdnestConfigService,
@Optional() cacheService?: CacheService,
) {
this.authServer = new NativeAuthServer({
const nativeAuthServerConfig: NativeAuthServerConfig = {
apiUrl: erdnestConfigService.getApiUrl(),
maxExpirySeconds: erdnestConfigService.getNativeAuthMaxExpirySeconds(),
acceptedOrigins: erdnestConfigService.getNativeAuthAcceptedOrigins(),
Expand All @@ -45,7 +46,15 @@ export class NativeAuthGuard implements CanActivate {
throw new Error('CacheService is not available in the context');
},
},
});
};

const acceptedOrigins = erdnestConfigService.getNativeAuthAcceptedOrigins();
const shouldAllowAllOrigins = acceptedOrigins && acceptedOrigins.length === 1 && acceptedOrigins[0] === '*';
if (shouldAllowAllOrigins) {
nativeAuthServerConfig.isOriginAccepted = () => true; // allow all origins
}

this.authServer = new NativeAuthServer(nativeAuthServerConfig);
}

static getOrigin(headers: Record<string, string>): string {
Expand Down
2 changes: 1 addition & 1 deletion packages/cache/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@multiversx/sdk-nestjs-cache",
"version": "3.7.7",
"version": "3.7.8",
"description": "Multiversx SDK Nestjs cache package",
"main": "lib/index.js",
"types": "lib/index.d.ts",
Expand Down
2 changes: 1 addition & 1 deletion packages/common/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@multiversx/sdk-nestjs-common",
"version": "3.7.7",
"version": "3.7.8",
"description": "Multiversx SDK Nestjs common package",
"main": "lib/index.js",
"types": "lib/index.d.ts",
Expand Down
2 changes: 1 addition & 1 deletion packages/elastic/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@multiversx/sdk-nestjs-elastic",
"version": "3.7.7",
"version": "3.7.8",
"description": "Multiversx SDK Nestjs elastic package",
"main": "lib/index.js",
"types": "lib/index.d.ts",
Expand Down
2 changes: 1 addition & 1 deletion packages/http/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@multiversx/sdk-nestjs-http",
"version": "3.7.7",
"version": "3.7.8",
"description": "Multiversx SDK Nestjs http package",
"main": "lib/index.js",
"types": "lib/index.d.ts",
Expand Down
2 changes: 1 addition & 1 deletion packages/monitoring/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@multiversx/sdk-nestjs-monitoring",
"version": "3.7.7",
"version": "3.7.8",
"description": "Multiversx SDK Nestjs monitoring package",
"main": "lib/index.js",
"types": "lib/index.d.ts",
Expand Down
2 changes: 1 addition & 1 deletion packages/rabbitmq/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@multiversx/sdk-nestjs-rabbitmq",
"version": "3.7.7",
"version": "3.7.8",
"description": "Multiversx SDK Nestjs rabbitmq client package",
"main": "lib/index.js",
"types": "lib/index.d.ts",
Expand Down
2 changes: 1 addition & 1 deletion packages/redis/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@multiversx/sdk-nestjs-redis",
"version": "3.7.7",
"version": "3.7.8",
"description": "Multiversx SDK Nestjs redis client package",
"main": "lib/index.js",
"types": "lib/index.d.ts",
Expand Down

0 comments on commit 93c9450

Please sign in to comment.