Skip to content
Merged
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/*
Copyright 2026 Google Inc. All rights reserved.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

import { mount } from '@vue/test-utils';
import Vuetify from 'vuetify';
import Vue from 'vue';
import { describe, it, expect, beforeEach } from 'vitest';
import LinkRedirectWarning from './LinkRedirectWarning.vue';

Vue.use(Vuetify);

describe('LinkRedirectWarning.vue', () => {
let vuetify;

beforeEach(() => {
vuetify = new Vuetify();
});

it('allows http/https contextUrl and does not double-escape ampersands', () => {
const wrapper = mount(LinkRedirectWarning, {
vuetify,
propsData: {
contextValue: 'a&b',
contextUrl: 'https://example.com/lookup?q=a&b=1',
},
});

expect(wrapper.vm.safeContextUrl).toBe('https://example.com/lookup?q=a&b=1');
expect(wrapper.text()).toContain('https://example.com/lookup?q=a&b=1');
expect(wrapper.text()).not.toContain('&');

const continueBtn = wrapper.findAll('.v-btn').at(1);
expect(continueBtn.attributes('href')).toBe('https://example.com/lookup?q=a&b=1');
expect(continueBtn.attributes('rel')).toBe('noopener noreferrer');
expect(continueBtn.attributes('disabled')).toBeUndefined();
});

it('blocks non-http(s) schemes in contextUrl and disables continue button', () => {
const wrapper = mount(LinkRedirectWarning, {
vuetify,
propsData: {
contextValue: 'payload',
contextUrl: 'javascript:alert(1)',
},
});

expect(wrapper.vm.safeContextUrl).toBeNull();
const continueBtn = wrapper.findAll('.v-btn').at(1);
expect(continueBtn.attributes('href')).toBeUndefined();
expect(continueBtn.attributes('disabled')).toBe('disabled');
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@ limitations under the License.
<div v-if="contextValue">
<b>Value:</b><br/>
<code class="code">
{{ getContextValue }}
{{ contextValue }}
</code>
</div>
<div>
<b>External website:</b><br/>
<code class="code">
{{ getContextUrl }}
{{ contextUrl }}
</code>
</div>

Expand All @@ -51,8 +51,10 @@ limitations under the License.
<v-btn
color="primary"
text
:href="contextUrl"
:href="safeContextUrl"
:disabled="!safeContextUrl"
target="_blank"
rel="noopener noreferrer"
@click="clearAndCancel"
>
continue
Expand All @@ -62,24 +64,30 @@ limitations under the License.
</template>

<script>
import DOMPurify from 'dompurify';

export default {
props: ['contextValue', 'contextUrl' ],
props: ['contextValue', 'contextUrl'],
methods: {
clearAndCancel: function () {
this.$emit('cancel')
this.$emit('cancel');
},
},
computed: {
getContextValue() {
return DOMPurify.sanitize(this.contextValue)
safeContextUrl() {
if (typeof this.contextUrl !== 'string') {
return null;
}
try {
const parsed = new URL(this.contextUrl);
if (parsed.protocol === 'http:' || parsed.protocol === 'https:') {
return parsed.href;
}
} catch {
return null;
}
return null;
},
getContextUrl() {
return DOMPurify.sanitize(this.contextUrl)
}
}
}
},
};
</script>

<style scoped lang="scss"></style>
69 changes: 69 additions & 0 deletions timesketch/frontend-ng/src/components/LeftPanel/SigmaRule.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/*
Copyright 2026 Google Inc. All rights reserved.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

import { mount, createLocalVue } from '@vue/test-utils';
import Vuetify from 'vuetify';
import Vuex from 'vuex';
import Vue from 'vue';
import { describe, it, expect, beforeEach } from 'vitest';
import SigmaRule from './SigmaRule.vue';

const localVue = createLocalVue();
localVue.use(Vuex);
Vue.use(Vuetify);

describe('SigmaRule.vue', () => {
let vuetify;
let store;

beforeEach(() => {
vuetify = new Vuetify();
store = new Vuex.Store({
state: {
sketch: { id: 1 },
},
});
});

it('renders references as plain text rather than clickable links', async () => {
const wrapper = mount(SigmaRule, {
localVue,
vuetify,
store,
propsData: {
sigmaRule: {
rule_uuid: '1234',
title: 'Suspicious Rule',
},
},
stubs: ['router-link'],
});

await wrapper.setData({
expanded: true,
detailedSigmaRule: {
references: [
'https://example.com/advisory',
'javascript:alert(document.domain)',
],
},
});

expect(wrapper.findAll('a').length).toBe(0);
expect(wrapper.text()).toContain('https://example.com/advisory');
expect(wrapper.text()).toContain('javascript:alert(document.domain)');
});
Comment thread
jaegeral marked this conversation as resolved.
Resolved
});
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,7 @@
<td>
<span v-if="key === 'references'">
<ul v-for="ref in value" :key="ref">
<li>
<a :href="ref" target="new">{{ ref }}</a>
</li>
<li>{{ ref }}</li>
Comment thread
jaegeral marked this conversation as resolved.
Resolved
</ul>
</span>
<span v-else-if="key === 'falsepositives'">
Expand Down Expand Up @@ -249,7 +247,7 @@
eventData.queryString = '*'
let chip = {
field: 'tag',
value: value,

Check warning on line 250 in timesketch/frontend-ng/src/components/LeftPanel/SigmaRule.vue

View workflow job for this annotation

GitHub Actions / ESLint-frontend-ng (24)

Expected property shorthand
type: 'term',
operator: 'must',
active: true,
Expand Down
Loading