Skip to content

Commit cd327ea

Browse files
committed
Always create new object if it's a top level context
1 parent fab4914 commit cd327ea

File tree

1 file changed

+17
-9
lines changed

1 file changed

+17
-9
lines changed

library/agent/Context.ts

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -86,17 +86,25 @@ export function runWithContext<T>(context: Context, fn: () => T) {
8686
return fn();
8787
}
8888

89-
// `attackDetected`, `consumedRateLimitForIP` and `consumedRateLimitForUser`
90-
// are carried over if there's an existing context
91-
// Only in case of a top level context, we should reset them first
92-
// This is more for tests than for real usage
93-
delete context.cache;
94-
delete context.attackDetected;
95-
delete context.consumedRateLimitForIP;
96-
delete context.consumedRateLimitForUser;
89+
// We need to create a new context without `attackDetected`, `consumedRateLimitForIP`, ...
90+
const topLevelContext: Context = {
91+
url: context.url,
92+
method: context.method,
93+
query: context.query,
94+
headers: context.headers,
95+
routeParams: context.routeParams,
96+
remoteAddress: context.remoteAddress,
97+
body: context.body,
98+
cookies: context.cookies,
99+
source: context.source,
100+
route: context.route,
101+
graphql: context.graphql,
102+
xml: context.xml,
103+
subdomains: context.subdomains,
104+
};
97105

98106
// If there's no context yet, we create a new context and run the function with it
99-
return ContextStorage.run(context, fn);
107+
return ContextStorage.run(topLevelContext, fn);
100108
}
101109

102110
/**

0 commit comments

Comments
 (0)