-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request from GHSA-qqrm-9grj-6v32
* maybe ok * fix * test wip * ✌️ * fix * if (res.ok) * validateContentTypeSetAsJsonLD * 条件を考慮し直す * その他の+json接尾辞が付いているメディアタイプも受け容れる * https://github.com/misskey-dev/misskey-ghsa-qqrm-9grj-6v32/pull/1#discussion_r1490999009 * add `; profile="https://www.w3.org/ns/activitystreams"` * application/ld+json;
- Loading branch information
Showing
8 changed files
with
157 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/* | ||
* SPDX-FileCopyrightText: syuilo and misskey-project | ||
* SPDX-License-Identifier: AGPL-3.0-only | ||
*/ | ||
|
||
import type { Response } from 'node-fetch'; | ||
|
||
export function validateContentTypeSetAsActivityPub(response: Response): void { | ||
const contentType = (response.headers.get('content-type') ?? '').toLowerCase(); | ||
|
||
if (contentType === '') { | ||
throw new Error('Validate content type of AP response: No content-type header'); | ||
} | ||
if ( | ||
contentType.startsWith('application/activity+json') || | ||
(contentType.startsWith('application/ld+json;') && contentType.includes('https://www.w3.org/ns/activitystreams')) | ||
) { | ||
return; | ||
} | ||
throw new Error('Validate content type of AP response: Content type is not application/activity+json or application/ld+json'); | ||
} | ||
|
||
const plusJsonSuffixRegex = /(application|text)\/[a-zA-Z0-9\.\-\+]+\+json/; | ||
|
||
export function validateContentTypeSetAsJsonLD(response: Response): void { | ||
const contentType = (response.headers.get('content-type') ?? '').toLowerCase(); | ||
|
||
if (contentType === '') { | ||
throw new Error('Validate content type of JSON LD: No content-type header'); | ||
} | ||
if ( | ||
contentType.startsWith('application/ld+json') || | ||
contentType.startsWith('application/json') || | ||
plusJsonSuffixRegex.test(contentType) | ||
) { | ||
return; | ||
} | ||
throw new Error('Validate content type of JSON LD: Content type is not application/ld+json or application/json'); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/* | ||
* SPDX-FileCopyrightText: syuilo and misskey-project | ||
* SPDX-License-Identifier: AGPL-3.0-only | ||
*/ | ||
|
||
process.env.NODE_ENV = 'test'; | ||
|
||
import { validateContentTypeSetAsActivityPub, validateContentTypeSetAsJsonLD } from '@/core/activitypub/misc/validator.js'; | ||
import { signup, uploadFile, relativeFetch } from '../utils.js'; | ||
import type * as misskey from 'misskey-js'; | ||
|
||
describe('validateContentTypeSetAsActivityPub/JsonLD (deny case)', () => { | ||
let alice: misskey.entities.SignupResponse; | ||
let aliceUploadedFile: any; | ||
|
||
beforeAll(async () => { | ||
alice = await signup({ username: 'alice' }); | ||
aliceUploadedFile = await uploadFile(alice); | ||
}, 1000 * 60 * 2); | ||
|
||
test('ActivityStreams: ファイルはエラーになる', async () => { | ||
const res = await relativeFetch(aliceUploadedFile.webpublicUrl); | ||
|
||
function doValidate() { | ||
validateContentTypeSetAsActivityPub(res); | ||
} | ||
|
||
expect(doValidate).toThrow('Content type is not'); | ||
}); | ||
|
||
test('JSON-LD: ファイルはエラーになる', async () => { | ||
const res = await relativeFetch(aliceUploadedFile.webpublicUrl); | ||
|
||
function doValidate() { | ||
validateContentTypeSetAsJsonLD(res); | ||
} | ||
|
||
expect(doValidate).toThrow('Content type is not'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters