Skip to content

Commit b0e35c5

Browse files
committed
fix: address code review and security review findings
Made-with: Cursor
1 parent 9604ea6 commit b0e35c5

5 files changed

Lines changed: 16 additions & 15 deletions

File tree

src/background/background.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,9 @@ export function initBackground() {
8787
// Remove DOM-dependent setFaviconCode since it's not needed in service worker
8888

8989
const fetchOpenReviewNoteJSON = async (url) => {
90-
const id = url.match(/id=([\w-]+)/)[1];
90+
const match = url.match(/id=([\w-]+)/);
91+
if (!match) return;
92+
const id = match[1];
9193
const api = `https://api.openreview.net/notes?id=${id}`;
9294
let response = await fetch(api);
9395
let json = await response.json();
@@ -101,7 +103,9 @@ export function initBackground() {
101103
};
102104

103105
const fetchOpenReviewForumJSON = async (url) => {
104-
const id = url.match(/id=([\w-]+)/)[1];
106+
const match = url.match(/id=([\w-]+)/);
107+
if (!match) return;
108+
const id = match[1];
105109
const api = `https://api.openreview.net/notes?forum=${id}`;
106110
let response = await fetch(api);
107111
let json = await response.json();

src/content_scripts/content_script.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,6 @@ $.extend($.easing, {
136136
},
137137
});
138138

139-
var PDF_TITLE_ITERS = 0;
140139

141140
/**
142141
* Centralizes HTML svg codes
@@ -450,12 +449,13 @@ const contentScriptMain = async ({
450449
const paper = state.papers[id];
451450
const maxWait = 60 * 1000;
452451
const maxIters = 20;
453-
while (PDF_TITLE_ITERS < maxIters) {
454-
const waitTime = Math.min(maxWait, 250 * 2 ** PDF_TITLE_ITERS);
452+
let pdfTitleIters = 0;
453+
while (pdfTitleIters < maxIters) {
454+
const waitTime = Math.min(maxWait, 250 * 2 ** pdfTitleIters);
455455
await sleep(waitTime);
456456
document.title = "";
457457
document.title = paper.title;
458-
PDF_TITLE_ITERS++;
458+
pdfTitleIters++;
459459
}
460460
};
461461
makeTitle(id);
@@ -660,6 +660,7 @@ const huggingfacePapers = (paper, url) => {
660660
const abstractH2 = queryAll("h2").find((h) => h.innerText.trim() === "Abstract");
661661
if (!abstractH2) {
662662
log("Missing 'Abstract' h2 title on HuggingFace paper page.");
663+
return;
663664
}
664665
const authorDiv = abstractH2.parentElement.previousElementSibling;
665666
log("Adding venue to HuggingFace paper page.");

src/options/options.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -919,7 +919,7 @@ const setupSync = async () => {
919919

920920
if (!ok) {
921921
if (error) {
922-
setHTML("pat-feedback", "Invalid PAT" + "<br/><br/>" + error);
922+
setHTML("pat-feedback", "Invalid PAT" + "<br/><br/>" + escapeHtml(String(error)));
923923
}
924924
hideId("pat-loader");
925925
await toggleSync({ hideAll: true });
@@ -944,7 +944,7 @@ const setupSync = async () => {
944944
const { ok, payload, error } = await getGist({ pat });
945945
if (!ok) {
946946
logError(error);
947-
setHTML("pat-feedback", error.response.data.message);
947+
setHTML("pat-feedback", escapeHtml(String(error.response.data.message)));
948948
} else {
949949
const { file, pat, gistId } = payload;
950950
log("Gist ID", gistId);

src/popup/js/templates.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export const getPaperInfoTable = (paper) => {
2121
if (paper.venue)
2222
tableData.push([
2323
"Publication",
24-
`<strong>${paper.venue} ${paper.year}</strong>`,
24+
`<strong>${escapeHtml(paper.venue)} ${escapeHtml(String(paper.year))}</strong>`,
2525
]);
2626
return /*html*/ `
2727
<table class="paper-info-table">

src/shared/js/utils/parsers.js

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1928,14 +1928,10 @@ export const autoTagPaper = async (paper) => {
19281928
let authorMatch = true;
19291929
try {
19301930
if (at.title) {
1931-
titleMatch = paper.title
1932-
.toLowerCase()
1933-
.includes(at.title.toLowerCase());
1931+
titleMatch = new RegExp(at.title, "i").test(paper.title);
19341932
}
19351933
if (at.author) {
1936-
authorMatch = paper.author
1937-
.toLowerCase()
1938-
.includes(at.author.toLowerCase());
1934+
authorMatch = new RegExp(at.author, "i").test(paper.author);
19391935
}
19401936
} catch (e) {
19411937
continue;

0 commit comments

Comments
 (0)