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

Jc/fix code smells #84

Open
wants to merge 7 commits into
base: dev
Choose a base branch
from
Open

Jc/fix code smells #84

wants to merge 7 commits into from

Conversation

johnpcooke94
Copy link
Contributor

Fixes the rest of the code smells in the front-end.

@sonarqubecloud
Copy link

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

0.0% 0.0% Coverage
0.0% 0.0% Duplication

@@ -41,6 +41,7 @@ class ConsolePopout extends Component<Props> {

this.externalWindow!.document.title = 'VM Popout';

// Sonarcloud thinks this line is a security issue
this.externalWindow!.addEventListener('beforeunload', (ev: BeforeUnloadEvent) => {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@jasekiw @Cliftonz Sonarcloud thinks this is a security issue because we aren't verifying the origin of the message that we're listening to. But this is a reference to a window that we opened ourselves, so I don't think there's any real security risk here? I could be wrong, just wanted to check before I marked the issue resolved on Sonarcloud.

Copy link
Member

Choose a reason for hiding this comment

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

Someone could intercept our call back to a users and put their own vnc messages in there.
I remember talking about this with Jason but I do not remember what we decided on.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Normally the solution is to just verify the event origin, which I tried, but the BeforeUnloadEvent type that we're using doesn't seem to have a origin property. So I'm not sure what the proper solution here would be, at least not without some significant refactoring.

Let's see if Jason has any ideas, he built this component.

Copy link
Contributor

Choose a reason for hiding this comment

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

@Cliftonz How could someone intercept our callback? They would have to do cross site scripting which would be an even worse exploit.

Copy link
Contributor

Choose a reason for hiding this comment

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

@Cliftonz We're talking about an event handler that asks the user if they are sure if they want to exit, how much damage could exploiting this method really do?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@jasekiw I'm with you here, I think. I can mark this as won't fix if you're okay with that.

Copy link
Contributor

Choose a reason for hiding this comment

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

we are ok with this

@@ -16,7 +16,7 @@ export interface UploadByUrlForm extends NamedUpload {
const NameSchema: ObjectSchemaDefinition<NamedUpload> = {name: string().required('Required').min(3, 'Must have at least 3 characters')};
const UploadFormSchema = object<UploadForm>({
...NameSchema,
file: object().nullable() as ObjectSchema<File>
file: object() as ObjectSchema<File>
Copy link
Contributor

Choose a reason for hiding this comment

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

This is a dangerous suggestion, it breaks the validation message but it was also broken before in a different way.

it should be this:

Suggested change
file: object() as ObjectSchema<File>
file: object<File>().nullable().required('File is required')

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Committed this change.

@@ -41,6 +41,7 @@ class ConsolePopout extends Component<Props> {

this.externalWindow!.document.title = 'VM Popout';

// Sonarcloud thinks this line is a security issue
this.externalWindow!.addEventListener('beforeunload', (ev: BeforeUnloadEvent) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

@Cliftonz How could someone intercept our callback? They would have to do cross site scripting which would be an even worse exploit.

@@ -41,6 +41,7 @@ class ConsolePopout extends Component<Props> {

this.externalWindow!.document.title = 'VM Popout';

// Sonarcloud thinks this line is a security issue
this.externalWindow!.addEventListener('beforeunload', (ev: BeforeUnloadEvent) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

@Cliftonz We're talking about an event handler that asks the user if they are sure if they want to exit, how much damage could exploiting this method really do?

@@ -3,7 +3,6 @@ import {BrowserTypes} from '../types/actionTypes';
import {WindowState} from '../types/BrowserState';
import Action from '../types/redux';

// Code smell on this function signature
function windowSize(state: WindowState = {height: NaN, width: NaN}, action: Action) {
Copy link
Contributor

Choose a reason for hiding this comment

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

This is how redux is designed to be used, this code smell needs to be disabled

Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Jason is right, if you try to flip it, it breaks redux. I marked this as a false positive.

@@ -9,12 +9,10 @@ import {persistGlobalStore, persistRootReducer} from './persistance';

const configureStore = (initialState?: DeepPartial<WebState>, onReady?: () => void) => {
const root = persistRootReducer(combineReducers(rootReducer(history)));
// @ts-ignore
Copy link
Contributor

Choose a reason for hiding this comment

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

This used to break without ts-ignore, it doesn't any more?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Well, it was working when I opened this PR. But now I've merged dev in and the linter is mad, so I'm not sure what changed. Either way I'll just put it back.

const composeEnhancers: typeof compose = (typeof window !== 'undefined' && window['__REDUX_DEVTOOLS_EXTENSION_COMPOSE__']) || compose;
const storeInstance = createStore(
root,
initialState,
// Code smell on this
Copy link
Contributor

Choose a reason for hiding this comment

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

This is completely false, it does change the type expressions and is necessary

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, that's why I removed this comment. I was using the comments to help me keep track of what code smells I hadn't fixed yet. Once I realized this was a false positive I removed the comment and marked the smell resolved.

@sonarqubecloud
Copy link

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

0.0% 0.0% Coverage
0.0% 0.0% Duplication

@johnpcooke94 johnpcooke94 marked this pull request as ready for review January 23, 2022 18:33
Copy link
Member

@Cliftonz Cliftonz left a comment

Choose a reason for hiding this comment

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

lgtm

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

Successfully merging this pull request may close these issues.

3 participants