Normalize URL path
Udates #2814 Otherwise `"` gets escaped as `"` by lit-html which is not correct.
This commit is contained in:
parent
9a2424fa26
commit
9a95c2d048
@ -611,7 +611,7 @@ describe("A Chat Message", function () {
|
|||||||
await u.waitUntil(() => view.querySelectorAll('.chat-msg__text').length === 4);
|
await u.waitUntil(() => view.querySelectorAll('.chat-msg__text').length === 4);
|
||||||
await u.waitUntil(() => {
|
await u.waitUntil(() => {
|
||||||
const text = view.querySelector('converse-chat-message:last-child .chat-msg__text').innerHTML.replace(/<!-.*?->/g, '');
|
const text = view.querySelector('converse-chat-message:last-child .chat-msg__text').innerHTML.replace(/<!-.*?->/g, '');
|
||||||
return text === 'Hey\nHave you heard\n\u200B\nthe news?\n<a target="_blank" rel="noopener" href="https://conversejs.org">https://conversejs.org</a>';
|
return text === 'Hey\nHave you heard\n\u200B\nthe news?\n<a target="_blank" rel="noopener" href="https://conversejs.org/">https://conversejs.org</a>';
|
||||||
});
|
});
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
@ -106,7 +106,7 @@ describe("An incoming chat Message", function () {
|
|||||||
expect(msg_el.innerText).toBe(msg_text);
|
expect(msg_el.innerText).toBe(msg_text);
|
||||||
await u.waitUntil(() => msg_el.innerHTML.replace(/<!-.*?->/g, '') ===
|
await u.waitUntil(() => msg_el.innerHTML.replace(/<!-.*?->/g, '') ===
|
||||||
'<span class="styling-directive">~</span>'+
|
'<span class="styling-directive">~</span>'+
|
||||||
'<del>Check out this site: <a target="_blank" rel="noopener" href="https://conversejs.org">https://conversejs.org</a></del>'+
|
'<del>Check out this site: <a target="_blank" rel="noopener" href="https://conversejs.org/">https://conversejs.org</a></del>'+
|
||||||
'<span class="styling-directive">~</span>');
|
'<span class="styling-directive">~</span>');
|
||||||
|
|
||||||
// Images inside directives aren't shown inline
|
// Images inside directives aren't shown inline
|
||||||
@ -182,7 +182,7 @@ describe("An incoming chat Message", function () {
|
|||||||
expect(msg_el.innerText).toBe(msg_text);
|
expect(msg_el.innerText).toBe(msg_text);
|
||||||
await u.waitUntil(() => msg_el.innerHTML.replace(/<!-.*?->/g, '') ===
|
await u.waitUntil(() => msg_el.innerHTML.replace(/<!-.*?->/g, '') ===
|
||||||
'Go to <span class="styling-directive">_</span>'+
|
'Go to <span class="styling-directive">_</span>'+
|
||||||
'<i><a target="_blank" rel="noopener" href="https://converse_js.org">https://converse_js.org</a></i>'+
|
'<i><a target="_blank" rel="noopener" href="https://converse_js.org/">https://converse_js.org</a></i>'+
|
||||||
'<span class="styling-directive">_</span> <span class="styling-directive">_</span><i>please</i><span class="styling-directive">_</span>');
|
'<span class="styling-directive">_</span> <span class="styling-directive">_</span><i>please</i><span class="styling-directive">_</span>');
|
||||||
|
|
||||||
}));
|
}));
|
||||||
|
@ -134,21 +134,21 @@ describe("XSS", function () {
|
|||||||
|
|
||||||
|
|
||||||
await u.waitUntil(() => msg.innerHTML.replace(/<!-.*?->/g, '') ===
|
await u.waitUntil(() => msg.innerHTML.replace(/<!-.*?->/g, '') ===
|
||||||
`<a target="_blank" rel="noopener" href="http://www.opkode.com/'onmouseover='alert(1)'whatever">http://www.opkode.com/\'onmouseover=\'alert(1)\'whatever</a>`);
|
`<a target="_blank" rel="noopener" href="http://www.opkode.com/%27onmouseover=%27alert%281%29%27whatever">http://www.opkode.com/\'onmouseover=\'alert(1)\'whatever</a>`);
|
||||||
|
|
||||||
message = 'http://www.opkode.com/"onmouseover="alert(1)"whatever';
|
message = 'http://www.opkode.com/"onmouseover="alert(1)"whatever';
|
||||||
await mock.sendMessage(view, message);
|
await mock.sendMessage(view, message);
|
||||||
msg = sizzle('.chat-content .chat-msg:last .chat-msg__text', view).pop();
|
msg = sizzle('.chat-content .chat-msg:last .chat-msg__text', view).pop();
|
||||||
expect(msg.textContent).toEqual(message);
|
expect(msg.textContent).toEqual(message);
|
||||||
await u.waitUntil(() => msg.innerHTML.replace(/<!-.*?->/g, '') ===
|
await u.waitUntil(() => msg.innerHTML.replace(/<!-.*?->/g, '') ===
|
||||||
`<a target="_blank" rel="noopener" href="http://www.opkode.com/"onmouseover="alert(1)"whatever">http://www.opkode.com/"onmouseover="alert(1)"whatever</a>`);
|
`<a target="_blank" rel="noopener" href="http://www.opkode.com/%22onmouseover=%22alert%281%29%22whatever">http://www.opkode.com/"onmouseover="alert(1)"whatever</a>`);
|
||||||
|
|
||||||
message = "https://en.wikipedia.org/wiki/Ender's_Game";
|
message = "https://en.wikipedia.org/wiki/Ender's_Game";
|
||||||
await mock.sendMessage(view, message);
|
await mock.sendMessage(view, message);
|
||||||
msg = sizzle('.chat-content .chat-msg:last .chat-msg__text', view).pop();
|
msg = sizzle('.chat-content .chat-msg:last .chat-msg__text', view).pop();
|
||||||
expect(msg.textContent).toEqual(message);
|
expect(msg.textContent).toEqual(message);
|
||||||
await u.waitUntil(() => msg.innerHTML.replace(/<!-.*?->/g, '') ===
|
await u.waitUntil(() => msg.innerHTML.replace(/<!-.*?->/g, '') ===
|
||||||
`<a target="_blank" rel="noopener" href="https://en.wikipedia.org/wiki/Ender's_Game">https://en.wikipedia.org/wiki/Ender's_Game</a>`);
|
`<a target="_blank" rel="noopener" href="https://en.wikipedia.org/wiki/Ender%27s_Game">https://en.wikipedia.org/wiki/Ender's_Game</a>`);
|
||||||
|
|
||||||
message = "<https://bugs.documentfoundation.org/show_bug.cgi?id=123737>";
|
message = "<https://bugs.documentfoundation.org/show_bug.cgi?id=123737>";
|
||||||
await mock.sendMessage(view, message);
|
await mock.sendMessage(view, message);
|
||||||
@ -162,14 +162,14 @@ describe("XSS", function () {
|
|||||||
msg = sizzle('.chat-content .chat-msg:last .chat-msg__text', view).pop();
|
msg = sizzle('.chat-content .chat-msg:last .chat-msg__text', view).pop();
|
||||||
expect(msg.textContent).toEqual(message);
|
expect(msg.textContent).toEqual(message);
|
||||||
await u.waitUntil(() => msg.innerHTML.replace(/<!-.*?->/g, '') ===
|
await u.waitUntil(() => msg.innerHTML.replace(/<!-.*?->/g, '') ===
|
||||||
`<<a target="_blank" rel="noopener" href="http://www.opkode.com/"onmouseover="alert(1)"whatever">http://www.opkode.com/"onmouseover="alert(1)"whatever</a>>`);
|
`<<a target="_blank" rel="noopener" href="http://www.opkode.com/%22onmouseover=%22alert%281%29%22whatever">http://www.opkode.com/"onmouseover="alert(1)"whatever</a>>`);
|
||||||
|
|
||||||
message = `https://www.google.com/maps/place/Kochstraat+6,+2041+CE+Zandvoort/@52.3775999,4.548971,3a,15y,170.85h,88.39t/data=!3m6!1e1!3m4!1sQ7SdHo_bPLPlLlU8GSGWaQ!2e0!7i13312!8i6656!4m5!3m4!1s0x47c5ec1e56f845ad:0x1de0bc4a5771fb08!8m2!3d52.3773668!4d4.5489388!5m1!1e2`
|
message = `https://www.google.com/maps/place/Kochstraat+6,+2041+CE+Zandvoort/@52.3775999,4.548971,3a,15y,170.85h,88.39t/data=!3m6!1e1!3m4!1sQ7SdHo_bPLPlLlU8GSGWaQ!2e0!7i13312!8i6656!4m5!3m4!1s0x47c5ec1e56f845ad:0x1de0bc4a5771fb08!8m2!3d52.3773668!4d4.5489388!5m1!1e2`
|
||||||
await mock.sendMessage(view, message);
|
await mock.sendMessage(view, message);
|
||||||
msg = sizzle('.chat-content .chat-msg:last .chat-msg__text', view).pop();
|
msg = sizzle('.chat-content .chat-msg:last .chat-msg__text', view).pop();
|
||||||
expect(msg.textContent).toEqual(message);
|
expect(msg.textContent).toEqual(message);
|
||||||
await u.waitUntil(() => msg.innerHTML.replace(/<!-.*?->/g, '') ===
|
await u.waitUntil(() => msg.innerHTML.replace(/<!-.*?->/g, '') ===
|
||||||
`<a target="_blank" rel="noopener" href="https://www.google.com/maps/place/Kochstraat+6,+2041+CE+Zandvoort/@52.3775999,4.548971,3a,15y,170.85h,88.39t/data=!3m6!1e1!3m4!1sQ7SdHo_bPLPlLlU8GSGWaQ!2e0!7i13312!8i6656!4m5!3m4!1s0x47c5ec1e56f845ad:0x1de0bc4a5771fb08!8m2!3d52.3773668!4d4.5489388!5m1!1e2">https://www.google.com/maps/place/Kochstraat+6,+2041+CE+Zandvoort/@52.3775999,4.548971,3a,15y,170.85h,88.39t/data=!3m6!1e1!3m4!1sQ7SdHo_bPLPlLlU8GSGWaQ!2e0!7i13312!8i6656!4m5!3m4!1s0x47c5ec1e56f845ad:0x1de0bc4a5771fb08!8m2!3d52.3773668!4d4.5489388!5m1!1e2</a>`);
|
`<a target="_blank" rel="noopener" href="https://www.google.com/maps/place/Kochstraat+6,+2041+CE+Zandvoort/@52.3775999,4.548971,3a,15y,170.85h,88.39t/data=%213m6%211e1%213m4%211sQ7SdHo_bPLPlLlU8GSGWaQ%212e0%217i13312%218i6656%214m5%213m4%211s0x47c5ec1e56f845ad:0x1de0bc4a5771fb08%218m2%213d52.3773668%214d4.5489388%215m1%211e2">https://www.google.com/maps/place/Kochstraat+6,+2041+CE+Zandvoort/@52.3775999,4.548971,3a,15y,170.85h,88.39t/data=!3m6!1e1!3m4!1sQ7SdHo_bPLPlLlU8GSGWaQ!2e0!7i13312!8i6656!4m5!3m4!1s0x47c5ec1e56f845ad:0x1de0bc4a5771fb08!8m2!3d52.3773668!4d4.5489388!5m1!1e2</a>`);
|
||||||
}));
|
}));
|
||||||
|
|
||||||
it("will avoid malformed and unsafe urls urls from rendering as anchors",
|
it("will avoid malformed and unsafe urls urls from rendering as anchors",
|
||||||
@ -189,7 +189,7 @@ describe("XSS", function () {
|
|||||||
|
|
||||||
const good_urls =[{
|
const good_urls =[{
|
||||||
entered: 'http://www.google.com',
|
entered: 'http://www.google.com',
|
||||||
href: 'http://www.google.com'
|
href: 'http://www.google.com/'
|
||||||
}, {
|
}, {
|
||||||
entered: 'https://www.google.com/',
|
entered: 'https://www.google.com/',
|
||||||
href: 'https://www.google.com/'
|
href: 'https://www.google.com/'
|
||||||
|
@ -163,7 +163,7 @@ describe("A XEP-0316 MEP notification", function () {
|
|||||||
await u.waitUntil(() => view.querySelectorAll('.chat-info').length === 1, 1000);
|
await u.waitUntil(() => view.querySelectorAll('.chat-info').length === 1, 1000);
|
||||||
expect(view.querySelector('.chat-info__message converse-rich-text').textContent.trim()).toBe(msg);
|
expect(view.querySelector('.chat-info__message converse-rich-text').textContent.trim()).toBe(msg);
|
||||||
expect(view.querySelector('.reason converse-rich-text').innerHTML.replace(/<!-.*?->/g, '').trim()).toBe(
|
expect(view.querySelector('.reason converse-rich-text').innerHTML.replace(/<!-.*?->/g, '').trim()).toBe(
|
||||||
'Check out <a target="_blank" rel="noopener" href="https://conversejs.org">https://conversejs.org</a>');
|
'Check out <a target="_blank" rel="noopener" href="https://conversejs.org/">https://conversejs.org</a>');
|
||||||
}));
|
}));
|
||||||
|
|
||||||
it("can be retracted by a moderator",
|
it("can be retracted by a moderator",
|
||||||
|
@ -7,9 +7,9 @@ function onClickXMPPURI (ev) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export default (uri, url_text) => {
|
export default (uri, url_text) => {
|
||||||
let href_text = url_text;
|
let href_text = uri.normalizePath().toString();
|
||||||
if (!uri._parts.protocol && !url_text.startsWith('http://') && !url_text.startsWith('https://')) {
|
if (!uri._parts.protocol && !url_text.startsWith('http://') && !url_text.startsWith('https://')) {
|
||||||
href_text = 'http://' + url_text;
|
href_text = 'http://' + href_text;
|
||||||
}
|
}
|
||||||
if (uri._parts.protocol === 'xmpp' && uri._parts.query === 'join') {
|
if (uri._parts.protocol === 'xmpp' && uri._parts.query === 'join') {
|
||||||
return html`
|
return html`
|
||||||
|
Loading…
Reference in New Issue
Block a user