Skip to content

Commit e28f887

Browse files
authored
Merge pull request Blockstream#38 from mempool/mononaut/protect-internal-apis
Protect internal apis
2 parents 649f28d + 281b699 commit e28f887

File tree

1 file changed

+21
-4
lines changed

1 file changed

+21
-4
lines changed

src/rest.rs

+21-4
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@ const TTL_SHORT: u32 = 10; // ttl for volatie resources
5151
const TTL_MEMPOOL_RECENT: u32 = 5; // ttl for GET /mempool/recent
5252
const CONF_FINAL: usize = 10; // reorgs deeper than this are considered unlikely
5353

54+
// internal api prefix
55+
const INTERNAL_PREFIX: &str = "internal";
56+
5457
#[derive(Serialize, Deserialize)]
5558
struct BlockValue {
5659
id: String,
@@ -726,7 +729,7 @@ fn handle_request(
726729
.ok_or_else(|| HttpError::not_found("Block not found".to_string()))?;
727730
json_response(txids, TTL_LONG)
728731
}
729-
(&Method::GET, Some(&"block"), Some(hash), Some(&"txs"), None, None) => {
732+
(&Method::GET, Some(&INTERNAL_PREFIX), Some(&"block"), Some(hash), Some(&"txs"), None) => {
730733
let hash = BlockHash::from_hex(hash)?;
731734
let txs = query
732735
.chain()
@@ -1165,7 +1168,14 @@ fn handle_request(
11651168
(&Method::GET, Some(&"mempool"), Some(&"txids"), None, None, None) => {
11661169
json_response(query.mempool().txids(), TTL_SHORT)
11671170
}
1168-
(&Method::GET, Some(&"mempool"), Some(&"txs"), Some(&"all"), None, None) => {
1171+
(
1172+
&Method::GET,
1173+
Some(&INTERNAL_PREFIX),
1174+
Some(&"mempool"),
1175+
Some(&"txs"),
1176+
Some(&"all"),
1177+
None,
1178+
) => {
11691179
let txs = query
11701180
.mempool()
11711181
.txs()
@@ -1175,7 +1185,7 @@ fn handle_request(
11751185

11761186
json_response(prepare_txs(txs, query, config), TTL_SHORT)
11771187
}
1178-
(&Method::POST, Some(&"mempool"), Some(&"txs"), None, None, None) => {
1188+
(&Method::POST, Some(&INTERNAL_PREFIX), Some(&"mempool"), Some(&"txs"), None, None) => {
11791189
let txid_strings: Vec<String> =
11801190
serde_json::from_slice(&body).map_err(|err| HttpError::from(err.to_string()))?;
11811191

@@ -1198,7 +1208,14 @@ fn handle_request(
11981208
Err(err) => http_message(StatusCode::BAD_REQUEST, err.to_string(), 0),
11991209
}
12001210
}
1201-
(&Method::GET, Some(&"mempool"), Some(&"txs"), last_seen_txid, None, None) => {
1211+
(
1212+
&Method::GET,
1213+
Some(&INTERNAL_PREFIX),
1214+
Some(&"mempool"),
1215+
Some(&"txs"),
1216+
last_seen_txid,
1217+
None,
1218+
) => {
12021219
let last_seen_txid = last_seen_txid.and_then(|txid| Txid::from_hex(txid).ok());
12031220
let txs = query
12041221
.mempool()

0 commit comments

Comments
 (0)