In law, a witness, or eyewitness, was an individual who was prepared to testify in court in a trial about an incident or event they observed or possessed knowledge about. Their testimony was called a witness statement.
A character witness was someone who could affirm certain details about one's character. In 2266, James T. Kirk offered to testify at Harry Mudd's trial as a character witness in lieu of leaving him behind on Rigel XII. Mudd was of the opinion that if Kirk did, they'd "throw away the key." (TOS: "Mudd's Women")
That year, the USS Enterprise computer began to list nine eyewitnesses who could identify Kodos the Executioner, but only got up to five before Kirk interrupted it: himself, Thomas Leighton, E. Molson, Kevin Riley and D. Eames. All were dead by that point except Kirk and Riley. (TOS: "The Conscience of the King")
In 2270, Kol-Tai was a defense witness to Doctor Leonard McCoy's actions during the mass-inoculation program on Dramia II. (TAS: "Albatross")
An expert witness was someone who had intimate knowledge or experience of a field or subject pertinent to a trial. In 2372, Benjamin Sisko asked Advocate Ch'Pok to testify at Worf's extradition hearing as an expert witness on the Klingon Empire. (DS9: "Rules of Engagement")
Informally[]
Outside of law, a witness was simply someone with firsthand experience of an event.
In approximately 3074, The Doctor's backup copy, the EMH backup module, referred to himself as "some sort of fossil" when he learned that roughly 700 years had passed and he didn't know what happened to the USS Voyager or its crew. Quarren assured him that he wasn't a fossil but rather a living witness to history. (VOY: "Living Witness")