Skip to content

Commit

Permalink
fix(cache): validate arweave id before setting it
Browse files Browse the repository at this point in the history
  • Loading branch information
atticusofsparta committed Feb 27, 2024
1 parent 81637f8 commit 5ba1175
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/common/caches/arns-remote-cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
import { ARNS_TESTNET_REGISTRY_TX } from '../../constants.js';
import { ARNS_TESTNET_REGISTRY_TX, ARWEAVE_TX_REGEX } from '../../constants.js';
import {
ArIOContract,
ArNSNameData,
Expand Down Expand Up @@ -43,6 +43,7 @@ export class ArNSRemoteCache implements ArIOContract {
logger?: DefaultLogger;
contractTxId?: string;
}) {
this.validateContractTxId(contractTxId);
this.contractTxId = contractTxId;
this.logger = logger;
this.http = new AxiosHTTPService({
Expand All @@ -51,6 +52,12 @@ export class ArNSRemoteCache implements ArIOContract {
});
}

private validateContractTxId(id: string) {
if (!ARWEAVE_TX_REGEX.test(id)) {
throw new Error(`Invalid contract tx id: ${id}`);
}
}

async getGateway({ address }: { address: string }) {
this.logger.debug(`Fetching gateway ${address}`);
const gateway = await this.getGateways().then((gateways) => {
Expand Down

0 comments on commit 5ba1175

Please sign in to comment.