Skip to content

Commit 4aa163b

Browse files
committed
Hide IP addresses from activity logs not generated by the user themselves
1 parent b570769 commit 4aa163b

File tree

5 files changed

+15
-18
lines changed

5 files changed

+15
-18
lines changed

app/Http/Controllers/Api/Client/ActivityLogController.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,7 @@ public function __invoke(ClientApiRequest $request): array
1616
{
1717
$activity = QueryBuilder::for($request->user()->activity())
1818
->with('actor')
19-
->allowedFilters([
20-
AllowedFilter::exact('ip'),
21-
AllowedFilter::partial('event'),
22-
])
19+
->allowedFilters([AllowedFilter::partial('event')])
2320
->allowedSorts(['timestamp'])
2421
->paginate(min($request->query('per_page', 25), 100))
2522
->appends($request->query());

app/Http/Controllers/Api/Client/Servers/ActivityLogController.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,7 @@ public function __invoke(ClientApiRequest $request, Server $server): array
2525
$activity = QueryBuilder::for($server->activity())
2626
->with('actor')
2727
->allowedSorts(['timestamp'])
28-
->allowedFilters([
29-
AllowedFilter::exact('ip'),
30-
AllowedFilter::partial('event'),
31-
])
28+
->allowedFilters([AllowedFilter::partial('event')])
3229
->when(config('activity.hide_admin_activity'), function (Builder $builder) use ($server) {
3330
// We could do this with a query and a lot of joins, but that gets pretty
3431
// painful so for now we'll execute a simpler query.

app/Transformers/Api/Client/ActivityLogTransformer.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public function transform(ActivityLog $model): array
2121
'batch' => $model->batch,
2222
'event' => $model->event,
2323
'is_api' => !is_null($model->api_key_id),
24-
'ip' => $model->ip,
24+
'ip' => optional($model->actor)->is($this->request->user()) ? $model->ip : null,
2525
'description' => $model->description,
2626
'properties' => $this->properties($model),
2727
'has_additional_metadata' => $this->hasAdditionalMetadata($model),
@@ -49,7 +49,11 @@ protected function properties(ActivityLog $model): array
4949
}
5050

5151
$properties = $model->properties
52-
->mapWithKeys(function ($value, $key) {
52+
->mapWithKeys(function ($value, $key) use ($model) {
53+
if ($key === 'ip' && !optional($model->actor)->is($this->request->user())) {
54+
return [$key => '[hidden]'];
55+
}
56+
5357
if (!is_array($value)) {
5458
return [$key => $value];
5559
}

resources/scripts/api/definitions/user/models.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ interface SSHKey extends Model {
2222
interface ActivityLog extends Model<'actor'> {
2323
batch: UUID | null;
2424
event: string;
25-
ip: string;
25+
ip: string | null;
2626
isApi: boolean;
2727
description: string | null;
2828
properties: Record<string, string | unknown>;

resources/scripts/components/elements/activity/ActivityLogEntry.tsx

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -75,13 +75,12 @@ export default ({ activity, children }: Props) => {
7575
<Translate ns={'activity'} values={properties} i18nKey={activity.event.replace(':', '.')} />
7676
</p>
7777
<div className={'mt-1 flex items-center text-sm'}>
78-
<Link
79-
to={`#${pathTo({ ip: activity.ip })}`}
80-
className={'transition-colors duration-75 active:text-cyan-400 hover:text-cyan-400'}
81-
>
82-
{activity.ip}
83-
</Link>
84-
<span className={'text-gray-400'}>&nbsp;|&nbsp;</span>
78+
{activity.ip && (
79+
<span>
80+
{activity.ip}
81+
<span className={'text-gray-400'}>&nbsp;|&nbsp;</span>
82+
</span>
83+
)}
8584
<Tooltip placement={'right'} content={format(activity.timestamp, 'MMM do, yyyy H:mm:ss')}>
8685
<span>{formatDistanceToNowStrict(activity.timestamp, { addSuffix: true })}</span>
8786
</Tooltip>

0 commit comments

Comments
 (0)