Skip to content

Commit dd2dbce

Browse files
authored
fix: Sanitize the Hyper Request included in the SDK response
2 parents 9423321 + e1f6a55 commit dd2dbce

2 files changed

Lines changed: 43 additions & 1 deletion

File tree

models/Subscriptions.cfc

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,20 @@ component singleton accessors="true" {
240240

241241
private struct function buildResponseResult( required string subscriberEmail, required any response ) {
242242
var memento = arguments.response.getMemento();
243-
memento[ "request" ] = arguments.response.getRequest().getMemento();
243+
memento[ "request" ] = arguments.response
244+
.getRequest()
245+
.getMemento(
246+
excludes = [
247+
"authType",
248+
"clientCert",
249+
"clientCertPassword",
250+
"domain",
251+
"headers",
252+
"password",
253+
"username",
254+
"workstation"
255+
]
256+
);
244257
return {
245258
"subscriber": arguments.subscriberEmail,
246259
"success": arguments.response.isSuccess(),

tests/specs/unit/SubscriptionsSpec.cfc

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,35 @@ component extends="tests.resources.ModuleIntegrationSpec" appMapping="/app" {
318318
expect( result.results[ 1 ].statusCode ).toBe( 429 );
319319
} );
320320

321+
it( "sanitizes request credentials from operation result response mementos", function() {
322+
var credentialedHyper = new Hyper.models.HyperBuilder(
323+
defaults = new Hyper.models.HyperRequest()
324+
.setUsername( "secret-api-key" )
325+
.setPassword( "secret-password" )
326+
).fake( {
327+
"*/v2/contacts": function( newFakeResponse, req ) {
328+
return newFakeResponse( 429, "Too Many Requests", "{}" );
329+
}
330+
} )
331+
.preventStrayRequests();
332+
333+
variables.client.setHyperClient( credentialedHyper );
334+
335+
var result = variables.client.create( listKey = "myList", subscribers = [ "person@example.com" ] );
336+
var requestMemento = result.results[ 1 ].response.request;
337+
338+
expect( requestMemento.method ).toBe( "POST" );
339+
expect( requestMemento.url ).toBe( "/v2/contacts" );
340+
expect( requestMemento ).notToHaveKey( "authType" );
341+
expect( requestMemento ).notToHaveKey( "clientCert" );
342+
expect( requestMemento ).notToHaveKey( "clientCertPassword" );
343+
expect( requestMemento ).notToHaveKey( "domain" );
344+
expect( requestMemento ).notToHaveKey( "headers" );
345+
expect( requestMemento ).notToHaveKey( "password" );
346+
expect( requestMemento ).notToHaveKey( "username" );
347+
expect( requestMemento ).notToHaveKey( "workstation" );
348+
} );
349+
321350
it( "marks cancel results as failed when Cordial returns non-2xx", function() {
322351
variables.hyper
323352
.fake( {

0 commit comments

Comments
 (0)