Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[INTERNAL][CORE] Adds security check for received activities #1067

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion core/src/saros/session/ISarosSession.java
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ void changePermission(User user, Permission permission)
Set<Integer> getUnavailableColors();

/** FOR INTERNAL USE ONLY ! */
void exec(List<IActivity> activities);
void exec(JID jid, List<IActivity> activities);

/**
* Adds an {@link IActivityProducer} so the production of its activities will be noticed.
Expand Down
4 changes: 2 additions & 2 deletions core/src/saros/session/internal/ActivitySequencer.java
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ private void executeActivities(
return;
}

sarosSession.exec(activities);
sarosSession.exec(sender, activities);
}

/** Sends an activity to the given recipients. */
Expand All @@ -359,7 +359,7 @@ public void sendActivity(List<User> recipients, final IActivity activity) {
new Runnable() {
@Override
public void run() {
sarosSession.exec(Collections.singletonList(activity));
sarosSession.exec(user.getJID(), Collections.singletonList(activity));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

getJID is deprecated. However, I found no alternative method (as e.g. getXMPPContact/getContact).
@stefaus How would you get the Contact/JID?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At the moment there is no proper replacement for everything where you need the contact plus the correct resource endpoint. XMPPContact can return the current best available JID, but this could change at any time.

the user.getJID() deprecation is really old, but until we have something better working this PR looks good to me

}
});
}
Expand Down
27 changes: 21 additions & 6 deletions core/src/saros/session/internal/SarosSession.java
Original file line number Diff line number Diff line change
Expand Up @@ -638,23 +638,38 @@ public ConcurrentDocumentClient getConcurrentDocumentClient() {
}

@Override
public void exec(List<IActivity> activities) {
public void exec(JID jid, List<IActivity> activities) {
/**
* @JTourBusStop 7, Activity sending, Incoming activities:
*
* <p>Incoming activities will arrive here. The ActivitySequencer calls this method for
* activities received over the Network Layer.
*/
final List<IActivity> valid = new ArrayList<IActivity>();
final List<IActivity> validActivities = new ArrayList<IActivity>();

// Check every incoming activity for validity
for (IActivity activity : activities) {
if (activity.isValid()) valid.add(activity);
else log.error("could not handle incoming activity: " + activity);

if (!activity.isValid()) {
log.error("could not handle incoming activity: " + activity);
continue;
}

final User source = activity.getSource();

assert jid != null && source != null;

if (isHost() && !source.getJID().strictlyEquals(jid)) {
log.warn("detected spoofed activity from: " + jid + " -> " + activity);
// TODO kick the user
continue;
}

validActivities.add(activity);
}

List<IActivity> processed = activityQueuer.process(valid);
activityHandler.handleIncomingActivities(processed);
final List<IActivity> executableActivites = activityQueuer.process(validActivities);
activityHandler.handleIncomingActivities(executableActivites);
}

/*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ private static ISarosSession createSessionMock(

final Capture<List<IActivity>> capture = Capture.newInstance();

session.exec(EasyMock.capture(capture));
session.exec(EasyMock.anyObject(JID.class), EasyMock.capture(capture));

EasyMock.expectLastCall()
.andAnswer(() -> receivedActivitiesBuffer.addAll(capture.getValue()))
Expand Down