mirror of
https://github.com/misskey-dev/summaly.git
synced 2025-08-07 16:54:01 +09:00
Compare commits
2 Commits
Author | SHA1 | Date | |
---|---|---|---|
5684f116c9 | |||
709ca51b6c |
@ -1,3 +1,11 @@
|
||||
3.0.4 / 2023-02-12
|
||||
------------------
|
||||
* 不要な依存関係を除去
|
||||
|
||||
3.0.3 / 2023-02-12
|
||||
------------------
|
||||
* agentが指定されている(もしくはagentが空のオブジェクトの)場合はプライベートIPのリクエストを許可
|
||||
|
||||
3.0.2 / 2023-02-12
|
||||
------------------
|
||||
* Fastifyのルーティングを'/'から'*'に
|
||||
|
@ -28,8 +28,8 @@ export async function scpaping(url, opts) {
|
||||
},
|
||||
typeFilter: /^(text\/html|application\/xhtml\+xml)/,
|
||||
});
|
||||
// テスト用
|
||||
const allowPrivateIp = process.env.SUMMALY_ALLOW_PRIVATE_IP === 'true';
|
||||
// SUMMALY_ALLOW_PRIVATE_IPはテスト用
|
||||
const allowPrivateIp = process.env.SUMMALY_ALLOW_PRIVATE_IP === 'true' || Object.keys(agent).length > 0;
|
||||
if (!allowPrivateIp && response.ip && PrivateIp(response.ip)) {
|
||||
throw new StatusError(`Private IP rejected ${response.ip}`, 400, 'Private IP Rejected');
|
||||
}
|
||||
|
1
built/utils/status-error.d.ts
vendored
1
built/utils/status-error.d.ts
vendored
@ -1,4 +1,5 @@
|
||||
export declare class StatusError extends Error {
|
||||
name: string;
|
||||
statusCode: number;
|
||||
statusMessage?: string;
|
||||
isPermanentError: boolean;
|
||||
|
1463
package-lock.json
generated
1463
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "summaly",
|
||||
"version": "3.0.1",
|
||||
"version": "3.0.4",
|
||||
"description": "Get web page's summary",
|
||||
"author": "syuilo <syuilotan@yahoo.co.jp>",
|
||||
"license": "MIT",
|
||||
@ -18,9 +18,6 @@
|
||||
"test": "node --experimental-vm-modules node_modules/jest/bin/jest.js --silent=false --verbose false",
|
||||
"serve": "fastify start ./built/index.js"
|
||||
},
|
||||
"optionalDependencies": {
|
||||
"fastify": "3.24.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@jest/globals": "^29.4.2",
|
||||
"@swc/core": "^1.3.35",
|
||||
@ -31,7 +28,6 @@
|
||||
"@types/html-entities": "1.3.4",
|
||||
"@types/node": "16.11.12",
|
||||
"debug": "^4.3.4",
|
||||
"express": "^4.18.2",
|
||||
"fastify": "^4.13.0",
|
||||
"fastify-cli": "^5.7.1",
|
||||
"jest": "^29.4.2",
|
||||
@ -44,7 +40,6 @@
|
||||
"html-entities": "2.3.2",
|
||||
"iconv-lite": "0.6.3",
|
||||
"jschardet": "3.0.0",
|
||||
"koa": "2.13.4",
|
||||
"private-ip": "2.3.3",
|
||||
"trace-redirect": "1.0.6"
|
||||
}
|
||||
|
@ -42,8 +42,8 @@ export async function scpaping(url: string, opts?: { lang?: string; }) {
|
||||
typeFilter: /^(text\/html|application\/xhtml\+xml)/,
|
||||
});
|
||||
|
||||
// テスト用
|
||||
const allowPrivateIp = process.env.SUMMALY_ALLOW_PRIVATE_IP === 'true';
|
||||
// SUMMALY_ALLOW_PRIVATE_IPはテスト用
|
||||
const allowPrivateIp = process.env.SUMMALY_ALLOW_PRIVATE_IP === 'true' || Object.keys(agent).length > 0;
|
||||
|
||||
if (!allowPrivateIp && response.ip && PrivateIp(response.ip)) {
|
||||
throw new StatusError(`Private IP rejected ${response.ip}`, 400, 'Private IP Rejected');
|
||||
|
@ -1,4 +1,5 @@
|
||||
export class StatusError extends Error {
|
||||
public name: string;
|
||||
public statusCode: number;
|
||||
public statusMessage?: string;
|
||||
public isPermanentError: boolean;
|
||||
|
@ -13,6 +13,9 @@ import { summaly } from '../src/index.js';
|
||||
import { dirname } from 'node:path';
|
||||
import { fileURLToPath } from 'node:url';
|
||||
import {expect, jest, test, describe, beforeEach, afterEach} from '@jest/globals';
|
||||
import { Agent as httpAgent } from 'node:http';
|
||||
import { Agent as httpsAgent } from 'node:https';
|
||||
import { StatusError } from '../src/utils/status-error.js';
|
||||
|
||||
const _filename = fileURLToPath(import.meta.url);
|
||||
const _dirname = dirname(_filename);
|
||||
@ -31,10 +34,14 @@ const host = `http://localhost:${port}`;
|
||||
// Display detail of unhandled promise rejection
|
||||
process.on('unhandledRejection', console.dir);
|
||||
|
||||
let app: ReturnType<typeof fastify>;
|
||||
let app: ReturnType<typeof fastify> | null = null;
|
||||
let n = 0;
|
||||
|
||||
afterEach(() => {
|
||||
if (app) return app.close();
|
||||
afterEach(async () => {
|
||||
if (app) {
|
||||
await app.close();
|
||||
app = null;
|
||||
}
|
||||
});
|
||||
|
||||
/* tests below */
|
||||
@ -66,7 +73,7 @@ test('faviconがHTML上で指定されていなくて、ルートにも存在し
|
||||
test('titleがcleanupされる', async () => {
|
||||
app = fastify();
|
||||
app.get('/', (request, reply) => {
|
||||
return reply.send(fs.createReadStream(_dirname + '/htmls/ditry-title.html'));
|
||||
return reply.send(fs.createReadStream(_dirname + '/htmls/dirty-title.html'));
|
||||
});
|
||||
await app.listen({ port });
|
||||
|
||||
@ -77,15 +84,39 @@ test('titleがcleanupされる', async () => {
|
||||
describe('Private IP blocking', () => {
|
||||
beforeEach(() => {
|
||||
process.env.SUMMALY_ALLOW_PRIVATE_IP = 'false';
|
||||
app = fastify();
|
||||
app.get('*', (request, reply) => {
|
||||
return reply.send(fs.createReadStream(_dirname + '/htmls/og-title.html'));
|
||||
});
|
||||
return app.listen({ port });
|
||||
});
|
||||
|
||||
test('private ipなサーバーの情報を取得できない', async () => {
|
||||
app = fastify();
|
||||
app.get('/', (request, reply) => {
|
||||
return reply.send(fs.createReadStream(_dirname + '/htmls/og-title.html'));
|
||||
const summary = await summaly(host).catch((e: StatusError) => e);
|
||||
if (summary instanceof StatusError) {
|
||||
expect(summary.name).toBe('StatusError');
|
||||
} else {
|
||||
expect(summary).toBeInstanceOf(StatusError);
|
||||
}
|
||||
});
|
||||
|
||||
test('agentが指定されている場合はprivate ipを許可', async () => {
|
||||
const summary = await summaly(host, {
|
||||
agent: {
|
||||
http: new httpAgent({ keepAlive: true }),
|
||||
https: new httpsAgent({ keepAlive: true }),
|
||||
}
|
||||
});
|
||||
await app.listen({ port });
|
||||
expect(() => summaly(host)).rejects.toMatch('Private IP rejected 127.0.0.1');
|
||||
expect(summary.title).toBe('Strawberry Pasta');
|
||||
});
|
||||
|
||||
test('agentが空のオブジェクトの場合はprivate ipを許可しない', async () => {
|
||||
const summary = await summaly(host, { agent: {} }).catch((e: StatusError) => e);
|
||||
if (summary instanceof StatusError) {
|
||||
expect(summary.name).toBe('StatusError');
|
||||
} else {
|
||||
expect(summary).toBeInstanceOf(StatusError);
|
||||
}
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
@ -96,7 +127,7 @@ describe('Private IP blocking', () => {
|
||||
describe('OGP', () => {
|
||||
test('title', async () => {
|
||||
app = fastify();
|
||||
app.get('/', (request, reply) => {
|
||||
app.get('*', (request, reply) => {
|
||||
return reply.send(fs.createReadStream(_dirname + '/htmls/og-title.html'));
|
||||
});
|
||||
await app.listen({ port });
|
||||
|
Reference in New Issue
Block a user