diff --git a/timesketch/frontend-ng/src/components/Explore/LinkRedirectWarning.test.js b/timesketch/frontend-ng/src/components/Explore/LinkRedirectWarning.test.js new file mode 100644 index 0000000000..6d759500fc --- /dev/null +++ b/timesketch/frontend-ng/src/components/Explore/LinkRedirectWarning.test.js @@ -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'); + }); +}); diff --git a/timesketch/frontend-ng/src/components/Explore/LinkRedirectWarning.vue b/timesketch/frontend-ng/src/components/Explore/LinkRedirectWarning.vue index 454c80f115..4e9934c442 100644 --- a/timesketch/frontend-ng/src/components/Explore/LinkRedirectWarning.vue +++ b/timesketch/frontend-ng/src/components/Explore/LinkRedirectWarning.vue @@ -28,13 +28,13 @@ limitations under the License.
Value:
- {{ getContextValue }} + {{ contextValue }}
External website:
- {{ getContextUrl }} + {{ contextUrl }}
@@ -51,8 +51,10 @@ limitations under the License. continue @@ -62,24 +64,30 @@ limitations under the License. diff --git a/timesketch/frontend-ng/src/components/LeftPanel/SigmaRule.test.js b/timesketch/frontend-ng/src/components/LeftPanel/SigmaRule.test.js new file mode 100644 index 0000000000..4a4c21578e --- /dev/null +++ b/timesketch/frontend-ng/src/components/LeftPanel/SigmaRule.test.js @@ -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)'); + }); +}); diff --git a/timesketch/frontend-ng/src/components/LeftPanel/SigmaRule.vue b/timesketch/frontend-ng/src/components/LeftPanel/SigmaRule.vue index 7af8eec2b4..e21ead530b 100644 --- a/timesketch/frontend-ng/src/components/LeftPanel/SigmaRule.vue +++ b/timesketch/frontend-ng/src/components/LeftPanel/SigmaRule.vue @@ -87,9 +87,7 @@ limitations under the License.