You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Ref: GHSA-j5g3-5c8r-7qfx
If a provided API key had characters that were invalid as
header values, usage reporting and schema reporting requests
would fail and log the API key.
This change implements two fixes to improve this:
* Trim the API key of any whitespace and log a warning
* Throw an error on startup if the key contains invalid characters
after being `.trim()`med.
`"Apollo Server requires either an existing schema, modules or typeDefs"`,
85
85
);
86
86
});
87
+
88
+
it('throws when an API key is not a valid header value',()=>{
89
+
expect(()=>{
90
+
newApolloServerBase({
91
+
typeDefs,
92
+
resolvers,
93
+
apollo: {
94
+
key: 'bar▒baz▒',
95
+
},
96
+
});
97
+
}).toThrowErrorMatchingInlineSnapshot(
98
+
`"The API key provided to Apollo Server contains characters which are invalid as HTTP header values. The following characters found in the key are invalid: ▒, ▒. Valid header values may only contain ASCII visible characters. If you think there is an issue with your key, please contact Apollo support."`,
99
+
);
100
+
});
101
+
102
+
it('trims whitespace from incoming API keys and logs a warning',()=>{
103
+
constlogger={
104
+
debug: jest.fn(),
105
+
info: jest.fn(),
106
+
warn: jest.fn(),
107
+
error: jest.fn(),
108
+
};
109
+
expect(()=>{
110
+
newApolloServerBase({
111
+
typeDefs,
112
+
resolvers,
113
+
apollo: {
114
+
key: 'barbaz\n',
115
+
},
116
+
logger,
117
+
});
118
+
}).not.toThrow();
119
+
expect(logger.warn).toHaveBeenCalledWith(
120
+
'The provided API key has unexpected leading or trailing whitespace. '+
121
+
'Apollo Server will trim the key value before use.',
`The API key provided to Apollo Server contains characters which are invalid as HTTP header values. The following characters found in the key are invalid: ${invalidChars.join(
90
+
', ',
91
+
)}. Valid header values may only contain ASCII visible characters. If you think there is an issue with your key, please contact Apollo support.`,
0 commit comments