Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
Kitsukey
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Kio!
Kitsukey
Commits
48223c1c
Commit
48223c1c
authored
6 years ago
by
mei23
Browse files
Options
Downloads
Patches
Plain Diff
Validate host in activity
parent
dddf7834
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/queue/processors/http/process-inbox.ts
+55
-0
55 additions, 0 deletions
src/queue/processors/http/process-inbox.ts
with
55 additions
and
0 deletions
src/queue/processors/http/process-inbox.ts
+
55
−
0
View file @
48223c1c
...
...
@@ -6,6 +6,8 @@ import parseAcct from '../../../misc/acct/parse';
import
User
,
{
IRemoteUser
}
from
'
../../../models/user
'
;
import
perform
from
'
../../../remote/activitypub/perform
'
;
import
{
resolvePerson
}
from
'
../../../remote/activitypub/models/person
'
;
import
{
toUnicode
}
from
'
punycode
'
;
import
{
URL
}
from
'
url
'
;
const
log
=
debug
(
'
misskey:queue:inbox
'
);
...
...
@@ -32,6 +34,15 @@ export default async (job: bq.Job, done: any): Promise<void> => {
return
;
}
// アクティビティ内のホストの検証
try
{
ValidateActivity
(
activity
,
host
);
}
catch
(
e
)
{
console
.
warn
(
e
);
done
();
return
;
}
user
=
await
User
.
findOne
({
usernameLower
:
username
,
host
:
host
.
toLowerCase
()
})
as
IRemoteUser
;
// アクティビティを送信してきたユーザーがまだMisskeyサーバーに登録されていなかったら登録する
...
...
@@ -39,6 +50,16 @@ export default async (job: bq.Job, done: any): Promise<void> => {
user
=
await
resolvePerson
(
activity
.
actor
)
as
IRemoteUser
;
}
}
else
{
// アクティビティ内のホストの検証
const
host
=
toUnicode
(
new
URL
(
signature
.
keyId
).
hostname
.
toLowerCase
());
try
{
ValidateActivity
(
activity
,
host
);
}
catch
(
e
)
{
console
.
warn
(
e
);
done
();
return
;
}
user
=
await
User
.
findOne
({
host
:
{
$ne
:
null
},
'
publicKey.id
'
:
signature
.
keyId
...
...
@@ -69,3 +90,37 @@ export default async (job: bq.Job, done: any): Promise<void> => {
done
(
e
);
}
};
/**
* Validate host in activity
* @param activity Activity
* @param host Expect host
*/
function
ValidateActivity
(
activity
:
any
,
host
:
string
)
{
// id (if exists)
if
(
typeof
activity
.
id
===
'
string
'
)
{
const
uriHost
=
toUnicode
(
new
URL
(
activity
.
id
).
hostname
.
toLowerCase
());
if
(
host
!==
uriHost
)
throw
new
Error
(
'
activity.id has different host
'
);
}
// actor (if exists)
if
(
typeof
activity
.
actor
===
'
string
'
)
{
const
uriHost
=
toUnicode
(
new
URL
(
activity
.
actor
).
hostname
.
toLowerCase
());
if
(
host
!==
uriHost
)
throw
new
Error
(
'
activity.actor has different host
'
);
}
// For Create activity
if
(
activity
.
type
===
'
Create
'
&&
activity
.
object
)
{
// object.id (if exists)
if
(
typeof
activity
.
object
.
id
===
'
string
'
)
{
const
uriHost
=
toUnicode
(
new
URL
(
activity
.
object
.
id
).
hostname
.
toLowerCase
());
if
(
host
!==
uriHost
)
throw
new
Error
(
'
activity.object.id has different host
'
);
}
// object.attributedTo (if exists)
if
(
typeof
activity
.
object
.
attributedTo
===
'
string
'
)
{
const
uriHost
=
toUnicode
(
new
URL
(
activity
.
object
.
attributedTo
).
hostname
.
toLowerCase
());
if
(
host
!==
uriHost
)
throw
new
Error
(
'
activity.object.attributedTo has different host
'
);
}
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment