Skip to content

[BUG] Cde injection possible through a weird struct tag #6

@9glenda

Description

@9glenda

Since struct tags are never (correct me if i am wrong) user controlled this is no security issue but it's still kinda a bug.

this will inject code:

type user struct {
    Injection  int `json:"test': number;\n}\n\nconsole.log('code injection');\ndeclare interface user2 {\n\t'aa"` 
}

will produce following ts code on the demo website.

declare interface user {
    'test': number;
}

console.log('code injection');
declare interface user2 {
	'aa': number;
}

image

The go json package warns about this being an invalid JSON tag so maybe the issue doesn't have to be addressed but I thought it's worth letting you know.

How to fix it?

don't let the user escape the string by using ' in the json tag.

maybe use the json package to tell rather it's even a valid json tag.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions