koa-cash 5.0.1 → 5.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.js +10 -2
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -155,14 +155,22 @@ module.exports = function (options) {
|
|
|
155
155
|
};
|
|
156
156
|
|
|
157
157
|
//
|
|
158
|
-
// if the content-type was `text` or started with `text/plain` then
|
|
158
|
+
// if the content-type was `text` or started with `text/plain` then
|
|
159
|
+
// check if the path extension is a known text/plain extension;
|
|
160
|
+
// if it has an extension that is NOT in the list, null the type
|
|
159
161
|
// (since it's likely cache poisoning or the default Koa `text` being used)
|
|
162
|
+
//
|
|
160
163
|
// NOTE: we use `startsWith` for `text/plain` to handle charset variations
|
|
161
164
|
// (e.g. `text/plain; charset=utf-8` which is Koa's default)
|
|
162
165
|
//
|
|
166
|
+
// NOTE: `path.extname()` returns the extension with a leading dot
|
|
167
|
+
// (e.g. `.txt`) but `TXT_EXTENSIONS` stores extensions without
|
|
168
|
+
// the dot (e.g. `txt`), so we strip the dot with `slice(1)`
|
|
169
|
+
//
|
|
163
170
|
if (obj.type === 'text' || obj.type?.startsWith('text/plain')) {
|
|
164
171
|
const ext = path.extname(ctx.path);
|
|
165
|
-
if (ext && !TXT_EXTENSIONS.has(ext.toLowerCase()))
|
|
172
|
+
if (ext && !TXT_EXTENSIONS.has(ext.slice(1).toLowerCase()))
|
|
173
|
+
obj.type = null;
|
|
166
174
|
}
|
|
167
175
|
|
|
168
176
|
const { fresh } = ctx.request;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "koa-cash",
|
|
3
3
|
"description": "HTTP response caching for Koa. HTTP response caching for Koa. Supports Redis, in-memory store, and more!",
|
|
4
|
-
"version": "5.0.
|
|
4
|
+
"version": "5.0.2",
|
|
5
5
|
"author": "Jonathan Ong <me@jongleberry.com> (http://jongleberry.com)",
|
|
6
6
|
"bugs": {
|
|
7
7
|
"url": "https://github.com/koajs/cash/issues",
|