Skip to content

Commit b2bae06

Browse files
committed
Sanitize request mementos in subscription results
1 parent 9423321 commit b2bae06

2 files changed

Lines changed: 41 additions & 1 deletion

File tree

models/Subscriptions.cfc

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,18 @@ 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+
"authType",
247+
"clientCert",
248+
"clientCertPassword",
249+
"domain",
250+
"headers",
251+
"password",
252+
"username",
253+
"workstation"
254+
] );
244255
return {
245256
"subscriber": arguments.subscriberEmail,
246257
"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)