Skip to content

Commit

Permalink
Protect internal bulk API endpoints behind /internal-api prefix
Browse files Browse the repository at this point in the history
  • Loading branch information
mononaut committed Aug 16, 2023
1 parent 572a1ec commit 4d372d4
Showing 1 changed file with 20 additions and 3 deletions.
23 changes: 20 additions & 3 deletions src/rest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ const TTL_SHORT: u32 = 10; // ttl for volatie resources
const TTL_MEMPOOL_RECENT: u32 = 5; // ttl for GET /mempool/recent
const CONF_FINAL: usize = 10; // reorgs deeper than this are considered unlikely

// internal api prefix
const INTERNAL_PREFIX: &str = "internal-api";

#[derive(Serialize, Deserialize)]
struct BlockValue {
id: String,
Expand Down Expand Up @@ -1129,7 +1132,14 @@ fn handle_request(
(&Method::GET, Some(&"mempool"), Some(&"txids"), None, None, None) => {
json_response(query.mempool().txids(), TTL_SHORT)
}
(&Method::GET, Some(&"mempool"), Some(&"txs"), Some(&"all"), None, None) => {
(
&Method::GET,
Some(&INTERNAL_PREFIX),
Some(&"mempool"),
Some(&"txs"),
Some(&"all"),
None,
) => {
let txs = query
.mempool()
.txs()
Expand All @@ -1139,7 +1149,7 @@ fn handle_request(

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

Expand All @@ -1162,7 +1172,14 @@ fn handle_request(
Err(err) => http_message(StatusCode::BAD_REQUEST, err.to_string(), 0),
}
}
(&Method::GET, Some(&"mempool"), Some(&"txs"), last_seen_txid, None, None) => {
(
&Method::GET,
Some(&INTERNAL_PREFIX),
Some(&"mempool"),
Some(&"txs"),
last_seen_txid,
None,
) => {
let last_seen_txid = last_seen_txid.and_then(|txid| Txid::from_hex(txid).ok());
let txs = query
.mempool()
Expand Down

0 comments on commit 4d372d4

Please sign in to comment.