Menu

Check the Parsed Origin of a Warehouse Endpoint
📰

Check the Parsed Origin of a Warehouse Endpoint

DEV Community: javascript·Tom·2 days ago
#uCtMHr5w
#devtojavascript#devto#dev#section#test
Reading 0:00
15s threshold

A configuration field is supposed to identify a warehouse endpoint. Checking that its text starts with the expected host can accept a different host with the same prefix. Supplying a trusted base to new URL() is also insufficient when the supplied value is already an absolute URL.

For a Shopify 3PL configuration review, compare the parsed origin against the exact configured origin. The URL constructor resolves relative references but does not force an absolute input to stay under its base. This local example accepts absolute HTTPS URLs for one illustrative origin, without embedded credentials or a fragment.

Parse first, then apply the declared rule

'use strict' ; const assert = require ( 'node:assert/strict' ) ;

const allowedOrigin = 'https://warehouse.example.test' ;

function checkedEndpoint ( text ) { if ( typeof text !== 'string' || text . length === 0 || text . trim ( ) !== text ) { throw new Error ( 'Exact nonempty URL text required' ) ; } const url = new URL ( text ) ; if ( url .…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.