Skip to content

Commit fe56d57

Browse files
committed
block swagger routes
1 parent 79b2062 commit fe56d57

10 files changed

Lines changed: 282 additions & 1 deletion

config/config.custom.cs-e2e.yaml

Lines changed: 217 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,217 @@
1+
network: 'chain'
2+
metaChainShardId: 4294967295
3+
api:
4+
public: true
5+
publicPort: 3001
6+
private: true
7+
privatePort: 4001
8+
websocket: true
9+
cron:
10+
cacheWarmer: false
11+
fastWarm: false
12+
queueWorker: false
13+
elasticUpdater: false
14+
flags:
15+
useRequestCaching: true
16+
useKeepAliveAgent: true
17+
useTracing: false
18+
useRequestLogging: false
19+
useVmQueryTracing: false
20+
processNfts: true
21+
collectionPropertiesFromGateway: false
22+
features:
23+
websocketSubscription:
24+
enabled: true
25+
port: 6002
26+
maxSubscriptionsPerInstance: 10000
27+
maxSubscriptionsPerClient: 10
28+
broadcastIntervalMs: 6000
29+
stateChanges:
30+
enabled: false
31+
port: 5675
32+
rabbitUrl: 'amqp://guest:guest@157.245.73.214:5672'
33+
exchange: 'state_accesses'
34+
queueName: 'api_state_accesses_queue-test'
35+
deadLetterExchange: 'api_state_accesses_queue_dlx'
36+
esdtEnabled: true
37+
eventsNotifier:
38+
enabled: false
39+
port: 5674
40+
url: 'amqp://guest:guest@127.0.0.1:5673'
41+
exchange: 'all_events'
42+
queue: 'api-process-logs-and-events'
43+
guestCaching:
44+
enabled: false
45+
hitsThreshold: 100
46+
ttl: 12
47+
transactionPool:
48+
enabled: true
49+
transactionPoolWarmer:
50+
enabled: false
51+
cronExpression: '*/5 * * * * *'
52+
ttlInSeconds: 60
53+
updateCollectionExtraDetails:
54+
enabled: false
55+
updateAccountExtraDetails:
56+
enabled: false
57+
marketplace:
58+
enabled: false
59+
serviceUrl: 'https://devnet-nfts-graph.multiversx.com/graphql'
60+
exchange:
61+
enabled: false
62+
serviceUrl: 'https://devnet-graph.xexchange.com/graphql'
63+
dataApi:
64+
enabled: false
65+
serviceUrl: 'https://devnet-data-api.multiversx.com'
66+
assetsFetch:
67+
enabled: false
68+
assetesUrl: 'https://tools.multiversx.com/assets-cdn'
69+
auth:
70+
enabled: false
71+
maxExpirySeconds: 86400
72+
acceptedOrigins:
73+
- ''
74+
admins:
75+
- ''
76+
jwtSecret: ''
77+
stakingV4:
78+
enabled: false
79+
cronExpression: '*/5 * * * * *'
80+
activationEpoch: 1043
81+
stakingV5:
82+
enabled: true
83+
activationEpoch: 4817
84+
chainBarnard:
85+
enabled: true
86+
activationEpoch: 1820
87+
activationTimestamp: 1753376544
88+
chainAndromeda:
89+
enabled: true
90+
activationEpoch: 4
91+
nodeEpochsLeft:
92+
enabled: false
93+
transactionProcessor:
94+
enabled: false
95+
maxLookBehind: 100
96+
transactionCompleted:
97+
enabled: false
98+
maxLookBehind: 100
99+
logLevel: 'Error'
100+
transactionBatch:
101+
enabled: false
102+
maxLookBehind: 100
103+
elasticCircuitBreaker:
104+
enabled: false
105+
durationThresholdMs: 5000
106+
failureCountThreshold: 5
107+
resetTimeoutMs: 30000
108+
elasticMigratedIndices:
109+
logs: 'events'
110+
statusChecker:
111+
enabled: false
112+
thresholds:
113+
tokens: 500
114+
nodes: 3000
115+
providers: 10
116+
tokenSupplyCount: 20
117+
tokenAssets: 20
118+
tokenAccounts: 500
119+
tokenTransactions: 500
120+
nodeValidators: 300
121+
nftScamInfo:
122+
enabled: false
123+
processNfts:
124+
enabled: false
125+
nftQueueName: 'api-process-nfts'
126+
deadLetterQueueName: 'api-process-nfts-dlq'
127+
tps:
128+
enabled: false
129+
maxLookBehindNonces: 100
130+
nodesFetch:
131+
enabled: true
132+
serviceUrl: 'https://devnet-api.multiversx.com'
133+
tokensFetch:
134+
enabled: true
135+
serviceUrl: 'https://devnet-api.multiversx.com'
136+
providersFetch:
137+
enabled: true
138+
serviceUrl: 'https://devnet-api.multiversx.com'
139+
image:
140+
width: 600
141+
height: 600
142+
type: 'png'
143+
aws:
144+
s3KeyId: ''
145+
s3Secret: ''
146+
s3Bucket: 'devnet-media.elrond.com'
147+
s3Region: ''
148+
s3Endpoint: ''
149+
urls:
150+
self: 'https://devnet-api.multiversx.com'
151+
elastic:
152+
- 'http://localhost:9200'
153+
gateway:
154+
- 'http://localhost:8085'
155+
verifier: 'https://play-api.multiversx.com'
156+
redis: '127.0.0.1'
157+
rabbitmq: 'amqp://127.0.0.1:5672'
158+
providers: 'https://devnet-delegation-api.multiversx.com/providers'
159+
delegation: 'https://devnet-delegation-api.multiversx.com'
160+
media: 'https://devnet-media.elrond.com'
161+
tmp: '/tmp'
162+
ipfs: 'https://ipfs.io/ipfs'
163+
socket: 'devnet-socket-api.multiversx.com'
164+
maiarId: 'https://devnet-id-api.multiversx.com'
165+
indexer:
166+
type: 'elastic'
167+
maxPagination: 10000
168+
database:
169+
enabled: true
170+
url: 'mongodb://root:secret@127.0.0.1:27017/api?authSource=admin'
171+
tls: false
172+
type: 'mysql'
173+
host: 'localhost'
174+
port: 3306
175+
username: 'root'
176+
password: 'root'
177+
database: 'api'
178+
caching:
179+
cacheTtl: 6
180+
processTtl: 600
181+
poolLimit: 50
182+
cacheDuration: 3
183+
keepAliveTimeout:
184+
downstream: 61000
185+
upstream: 60000
186+
contracts:
187+
esdt: 'erd1qqqqqqqqqqqqqqqpqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqzllls8a5w6u'
188+
auction: 'erd1qqqqqqqqqqqqqqqpqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqplllst77y4l'
189+
staking: 'erd1qqqqqqqqqqqqqqqpqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqllls0lczs7'
190+
delegationManager: 'erd1qqqqqqqqqqqqqqqpqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqylllslmq6y6'
191+
delegation: 'erd1qqqqqqqqqqqqqpgq97wezxw6l7lgg7k9rxvycrz66vn92ksh2tssxwf7ep'
192+
metabonding: 'erd1qqqqqqqqqqqqqpgqkg7we73j769ew5we4yyx7uyvnn0nefqgd8ssm6vjc2'
193+
inflation:
194+
- 1952123
195+
- 1746637
196+
- 1541150
197+
- 1335663
198+
- 1130177
199+
- 924690
200+
- 719203
201+
stakingV5Inflation:
202+
- 1069805
203+
nftProcess:
204+
parallelism: 1
205+
maxRetries: 3
206+
compression:
207+
enabled: true
208+
level: 6
209+
threshold: 1024
210+
chunkSize: 16384
211+
pubSubListener:
212+
enabled: false
213+
restrictedRoutes:
214+
enabled: true
215+
routes:
216+
- '/package.json'
217+
- '/docs/package.json'

config/config.devnet-old.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,3 +129,8 @@ inflation:
129129
nftProcess:
130130
parallelism: 1
131131
maxRetries: 3
132+
restrictedRoutes:
133+
enabled: true
134+
routes:
135+
- '/package.json'
136+
- '/docs/package.json'

config/config.devnet.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,3 +204,8 @@ compression:
204204
level: 6
205205
threshold: 1024
206206
chunkSize: 16384
207+
restrictedRoutes:
208+
enabled: true
209+
routes:
210+
- '/package.json'
211+
- '/docs/package.json'

config/config.e2e-mocked.mainnet.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,3 +86,8 @@ test:
8686
transaction-action:
8787
mex:
8888
microServiceUrl: 'https://graph.xexchange.com/graphql'
89+
restrictedRoutes:
90+
enabled: true
91+
routes:
92+
- '/package.json'
93+
- '/docs/package.json'

config/config.e2e.mainnet.yaml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,4 +197,9 @@ stakingV5Inflation:
197197
- 1262802
198198
nftProcess:
199199
parallelism: 1
200-
maxRetries: 3
200+
maxRetries: 3
201+
restrictedRoutes:
202+
enabled: true
203+
routes:
204+
- '/package.json'
205+
- '/docs/package.json'

config/config.mainnet.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,3 +212,9 @@ customUrlHeaders:
212212
- urlPattern: ''
213213
headers:
214214
x-custom-auth: ''
215+
restrictedRoutes:
216+
enabled: true
217+
routes:
218+
- '/package.json'
219+
- '/docs/package.json'
220+

config/config.testnet.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,3 +207,8 @@ compression:
207207
level: 6
208208
threshold: 1024
209209
chunkSize: 16384
210+
restrictedRoutes:
211+
enabled: true
212+
routes:
213+
- '/package.json'
214+
- '/docs/package.json'

src/common/api-config/api.config.service.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1104,4 +1104,12 @@ export class ApiConfigService {
11041104

11051105
return timestamp;
11061106
}
1107+
1108+
isRestrictedRoutesEnabled(): boolean {
1109+
return this.configService.get<boolean>('restrictedRoutes.enabled') ?? false;
1110+
}
1111+
1112+
getRestrictedRoutes(): string[] {
1113+
return this.configService.get<string[]>('restrictedRoutes.routes') ?? [];
1114+
}
11071115
}

src/main.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ import * as requestIp from 'request-ip';
3838
import compression from 'compression';
3939
import { IoAdapter } from '@nestjs/platform-socket.io';
4040
import { WebsocketSubscriptionModule } from './crons/websocket/websocket.subscription.module';
41+
import { RestrictedRoutesMiddleware } from './utils/restricted.routes.middleware';
4142

4243
async function bootstrap() {
4344
const logger = new Logger('Bootstrapper');
@@ -186,9 +187,16 @@ async function bootstrap() {
186187
logger.log(`Guest caching enabled: ${apiConfigService.isGuestCacheFeatureActive()}`);
187188
logger.log(`Transaction pool enabled: ${apiConfigService.isTransactionPoolEnabled()}`);
188189
logger.log(`Transaction pool cache warmer enabled: ${apiConfigService.isTransactionPoolCacheWarmerEnabled()}`);
190+
191+
logger.log('Restricted routes enabled: ' + apiConfigService.isRestrictedRoutesEnabled());
189192
}
190193

191194
async function configurePublicApp(publicApp: NestExpressApplication, apiConfigService: ApiConfigService) {
195+
if (apiConfigService.isRestrictedRoutesEnabled()) {
196+
const restrictedRoutesMiddleware = new RestrictedRoutesMiddleware(apiConfigService);
197+
publicApp.use(restrictedRoutesMiddleware.use.bind(restrictedRoutesMiddleware));
198+
}
199+
192200
if (apiConfigService.getCompressionEnabled()) {
193201
publicApp.use(compression({
194202
filter: (req: any, res: any) => {
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { NestMiddleware, NotFoundException } from '@nestjs/common';
2+
import { Request, Response, NextFunction } from 'express';
3+
import { ApiConfigService } from 'src/common/api-config/api.config.service';
4+
5+
export class RestrictedRoutesMiddleware implements NestMiddleware {
6+
constructor(
7+
private readonly apiConfigService: ApiConfigService,
8+
) { }
9+
use(req: Request, _res: Response, next: NextFunction) {
10+
const restrictedRoutes = this.apiConfigService.getRestrictedRoutes();
11+
if (restrictedRoutes.includes(req.path)) {
12+
throw new NotFoundException(`Cannot GET ${req.path}`);
13+
}
14+
15+
next();
16+
}
17+
}

0 commit comments

Comments
 (0)