Skip to content
This repository has been archived by the owner on Oct 2, 2018. It is now read-only.

Frontend passes target to backend #119

Closed
wants to merge 13 commits into from
Closed

Frontend passes target to backend #119

wants to merge 13 commits into from

Conversation

Masclins
Copy link
Collaborator

This resolves #78.

But after this and #115 everything is really ugly.

Philosophy goes as following:
Cards in hand have an attribute add-power equal to its add-power ability or "undefined".
When a card is "played", if add-power === "undefined" the play is passed to the backend, with target: "nil". Otherwise it gets an attribute row-played with the row where it's been played.
When a card on the board is clicked with a card "played" (that means it must be a card with an add-power !== "undefined" previously dragged/clicked) the "played" card recieves an attribute target: "[:rows 0 :cards 0]" with 0's being the appropriate indexes (even I can see the ugliness in that).

On the other hand, backend recieves always a target, and api.base/play-card-as-player understand the target (a string) as a clojure code giving the path (using (let [target (load-string target)].

From this pull-request (and the previous one) I see a couple of things that need work:

  • We should decide how to handle targets. I coded everything regarding targets and most probably are suboptimal (I'm being really generous here).
  • We are leaving a lot of work to the frontend, like deciding which cards need a target.
  • Attribute-setting and calls to play() are done in many places on the frontend code. That's weird and messy.

(play-card-as-player game-id player index row-id "nil"))
([game-id player index row-id target]
(let [game-state (persistence/fetch-game game-id)
target (load-string target)]
Copy link
Owner

Choose a reason for hiding this comment

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

load-string is a security issue, it is executing arbitrary Clojure code contained in a string received from an external connection.
A malicious user could alter the value being sent as target and run any kind of code on the system, compromising the entire backend.

Copy link
Owner

Choose a reason for hiding this comment

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

Just as a reminder: this pull request cannot be accepted until it doesn't use vulnerable things such as load-string

card.setAttribute("add-power", 1);
play.playCard(card);
expect(card.style.background).toBe("yellow");

card.setAttribute("target", 1);
card.setAttribute("target", "[:rows 0 :cards 0]");
Copy link
Owner

Choose a reason for hiding this comment

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

We cannot send Clojure code. Either split the information into target-row and target-card or use a json-encoded object

Copy link
Owner

Choose a reason for hiding this comment

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

The removal of load-string makes this change now incorrect, right?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This test only checks the card has a target, it doesn't checks if the target is correct.

@Masclins
Copy link
Collaborator Author

Now it passes the backend and frontend tests, but not the e2e.
So I think it's pretty obvious that the problem comes with the REST api.
Any help?

@kenan-rhoton kenan-rhoton changed the base branch from master to develop August 30, 2018 16:55
kenan-rhoton and others added 5 commits August 31, 2018 15:33
* small changes

* tests already done

* forgot an include
* small changes

* backend structure changes

* tests already done

* forgot an include

* readme

* remove changelog

* some rework

* english
@Masclins Masclins closed this Sep 6, 2018
@Masclins Masclins deleted the com-target branch September 6, 2018 16:47
@kenan-rhoton
Copy link
Owner

@Masclins Just to confirm, you dropped this on purpose, right?

@Masclins
Copy link
Collaborator Author

Masclins commented Sep 6, 2018

I dropped this because branch was deleted and pushed unto your repository.
We can either merge the branch and @pernilsalat makes his changes on a new branch, or we wait until he improves this one.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Communication of playing a card with targets
2 participants